arrays - PHP Multidimension in_array -
i've got 2 dimensional array looking this:
array ( [google.fr] => array ( [0] => array ( [0] => google.de [1] => microsoft.de [2] => google.com [3] => apple.de ) )
what need check is, if string first dimension - here google.fr
equal string comparing to. found thread here in stackoverflow provided following function:
function in_array_r($needle, $haystack, $strict = true) { foreach ($haystack $item) { if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) { return true; } } return false; }
i'm calling follows:
if (in_array_r($row->name, $linkresult)) { echo "<span style=color:red; margin-left:15px;> <b>!</b></span>"; }
but no matter in $row->name
, returns false. missing?
as said, google.fr
"the string first dimension".
it's array key, should compare input string key (at least first pass).
change function code shown below:
function in_array_r($needle, $haystack, $strict = true) { foreach ($haystack $k => $item) { if (($strict ? $k === $needle : $k == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) { return true; } } return false; } var_dump(in_array_r('google.fr', $linkresult)); // outputs "true"
Comments
Post a Comment