我正在尝试调试我编写的脚本,并且有一个问题归结为检查标识符是否存在于(多维)资产数组中。我正在使用从这个问题中得到的递归搜索的 in_array 函数。
这是功能:
function in_array_r($needle, $haystack, $strict = false) {
foreach ($haystack as $item) {
if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
return true;
}
}
return false;
}
我正在使用这些数据:
针: 'B51MM36'大海捞针
:(为未美化的阵列道歉 - 找不到美化的方法var_export
)
$sedols = array ( 0 => array ( 'ipsid' => '72', 'buyList' => '1', 'sedol' => 'B8LFDR7', 'isin' => 'LU0827876409', 'currency' => NULL, 'hedged' => '0', 'acc' => '0', 'inst' => '0', 'description' => 'BlackRock European Long Only', 'nonUKsitus' => '0', 'reportingStatus' => '0', 'matchScore' => 0, ), 1 => array ( 'ipsid' => '72', 'buyList' => '1', 'sedol' => 'LU0827876151', 'isin' => 'LU0827876151', 'currency' => 'USD', 'hedged' => '1', 'acc' => '1', 'inst' => '0', 'description' => 'Blackrock European Long Only', 'nonUKsitus' => '0', 'reportingStatus' => '0', 'matchScore' => 0, ), 2 => array ( 'ipsid' => '72', 'buyList' => '1', 'sedol' => 'LU0406496546 ', 'isin' => 'LU0406496546 ', 'currency' => 'EUR', 'hedged' => '1', 'acc' => '1', 'inst' => '0', 'description' => 'Blackrock European Long Only', 'nonUKsitus' => '0', 'reportingStatus' => '0', 'matchScore' => 0, ), 3 => array ( 'ipsid' => '72', 'buyList' => '1', 'sedol' => 'LU0827876409', 'isin' => 'LU0827876409', 'currency' => 'GBP', 'hedged' => '1', 'acc' => '0', 'inst' => '0', 'description' => 'Blackrock European Long Only', 'nonUKsitus' => '0', 'reportingStatus' => '1', 'matchScore' => 1, ), );
当我运行var_dump(in_array_r('B51MM36', $sedols));
它时输出bool(true)
。我很困惑,因为字符串'B51MM36'
没有出现在 haystack 数组中的任何位置。谁能确定这里发生了什么?