我有以下将遍历多维数组的 php 搜索脚本。当找到 $value 时,它会返回它,但我也希望返回地址(考虑到它只有 2 个级别)
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\n";
// return $value; // should return array with [?],[$key],[$value]
}
}
return false;
}
您会注意到 $key 是找到的最新数组的地址。但我想拥有父数组的索引。
数组示例:
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
)
)