note 89449 deleted from function.in-array by cmb
| From: | cmb@php.net | Date: | Sun, 15 Sep 2019 13:05:21 +0000 |
| Subject: | note 89449 deleted from function.in-array by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212193@lists.php.net to get a copy of this message | ||
Note Submitter: brouwer dot p at gmail dot com
----
If made a in_array function that checks if the specified key matches. It works recursivly so it
doesn't matter how deep your input array is.
<?php
function myInArray($array, $value, $key){
//loop through the array
foreach ($array as $val) {
//if $val is an array cal myInArray again with $val as array input
if(is_array($val)){
if(myInArray($val,$value,$key))
return true;
}
//else check if the given key has $value as value
else{
if($array[$key]==$value)
return true;
}
}
return false;
}
?>