note 72139 deleted from function.array-search by levim
| From: | levim@php.net | Date: | Mon, 24 Feb 2014 22:41:14 +0000 |
| Subject: | note 72139 deleted from function.array-search by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-198649@lists.php.net to get a copy of this message | ||
Note Submitter: erick dot xavier at gmail dot com
----
Modifing the "multiarray_search" to unordered Array....
<?PHP
function multiarray_search($arrayVet, $campo, $valor){
while(isset($arrayVet[key($arrayVet)])){
if($arrayVet[key($arrayVet)][$campo] == $valor){
return key($arrayVet);
}
next($arrayVet);
}
return -1;
}
//I.e.:
$myArr = array(
13 => array(
"fruit" => "banana"
),
654 => array(
"fruit" => "apple"
),
2445 => array(
"fruit" => "nothing more"
)
);
print(multiarray_search($myArr , "fruit", "apple"));
/*
Output:
654
*/
//and
print(multiarray_search($myArr , "fruit", "orange"));
/*
Output:
-1
*/
?>