我有以下阵列(称为$example_array
下):匹配递归/多维数组对另一个阵列
array(3) {
["id"]=> string(4) "123"
["name"]=>
array(1) {
["first"]=> string(3) "pete"
["last"]=> string(3) "foo"
}
["address"]=>
array(1) {
["shipping"]=>
array(1) {
["zip"]=> string(4) "1234"
["country"]=> string(4) "USA"
}
}
}
我想,我可以运行对数组这样,寻找一个匹配功能。下面是我想能够执行搜索:
// These should return true:
search($example_array, array('id' => '123'));
search($example_array, array('name' => array('first' => 'pete'));
search($example_array, array('address' => array('shipping' => array('country' => 'USA')));
// These don't have to return true:
search($example_array, array('first' => 'pete'));
search($example_array, array('country' => 'USA'));
有没有我可以使用PHP内部函数或我将不得不编写自己的东西?
是应该在阵列匹配或分开这三个阵列?匹配的逻辑是什么?如果项目匹配,如果其中的一个数组应该被搜索或全部匹配? – Leri
另外,每个都是可以针对示例数组执行搜索的示例。 –
看起来像数据库作业 –