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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -