$myArray
(
[0] => Array
(
[0] => 27
[1] => 87
[2] => 76
[3] => 37
[4] => 69
)
[1] => Array
(
[0] => 2
[1] => 43
[2] => 56
[3] => 26
[4] => 60
)
[2] => Array
(
[0] => 36
[1] => 29
[2] => 59
[3] => 13
[4] => 65
)
[3] => Array
(
[0] => 63
[1] => 26
[2] => 29
[3] => 59
[4] => 28
)
)
我有 $myArray。我想获取指定数字的主数组索引。
例如:如果数字是37,我想得到0。如果数字是56,我想得到1。如果数字是69,我想得到0。如果数字是28,我想得到3。
我尝试使用以下函数,但得到 0。也许有错误?!?
function search2dArray($needle, $haystack) {
if (is_array($haystack)) {
for ($h = 0; $h < count($haystack); $h++) {
$arraySearch = array_keys($haystack[$h], $needle);
if ($arraySearch != 0) {
return $h;
}
}
} else {
return false;
}
}
echo search2dArray(60, $myArray);
请问你能帮我吗?