note 71746 modified in function.array-search by danbrown

From: Date: Wed, 29 Apr 2009 12:59:48 +0000
Subject: note 71746 modified in function.array-search by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153982@lists.php.net to get a copy of this message
Unlimited depth array regular expression search, I found it useful, perhaps someone else will too. Searches on the array values only. Key search could be easily added. <?php function Array_Search_Preg( $find, $in_array, $keys_found=Array() ) { if( is_array( $in_array ) ) { foreach( $in_array as $key=> $val ) { if( is_array( $val ) ) $this->Array_Search_Preg( $find, $val, $keys_found ); else { if( preg_match( '/'. $find .'/', $val ) ) $keys_found[] = $key; } } return $keys_found; } return false; } ?> --was-- Unlimited depth array regular expression search, I found it useful, perhaps someone else will too. Searches on the array values only. Key search could be easily added. function Array_Search_Preg( $find, $in_array, $keys_found=Array() ) { if( is_array( $in_array ) ) { foreach( $in_array as $key=> $val ) { if( is_array( $val ) ) $this->Array_Search_Preg( $find, $val, $keys_found ); else { if( preg_match( '/'. $find .'/', $val ) ) $keys_found[] = $key; } } return $keys_found; } return false; } http://php.net/manual/en/function.array-search.php

« previous php.notes (#153982) next »