i have the below php search script that will traverse a multidimentional array. when $value is found it will return it, but i wish to return the address as well (considering it is only 2 levels)
function arr_search($array, $line, $lvl=0)
{
// Loops through each element. If element again is array, function is recalled. If not, result is echoed.
foreach($array as $key=>$value)
{
if(is_array($value))
{
arr_search($value, $line);
}else{
if(strpos($line, $value))
echo "found $key: $value
";
// return $value; // should return array with [?],[$key],[$value]
}
}
return false;
}
you can notice that $key is the address of the latest array found. but i want to have the index of the parent array.
array example:
Array
(
[0] => Array
(
[0] => string324
[1] => string234
[2] => string7567
[3] => stringw34
)
[1] => Array
(
[0] => string4563
[1] => string37
)
[2] => Array
(
[0] => string3735
[1] => string3563
[2] => string3563
[3] => string356
[4] => string356
)
)