i有2个数组,DataArray()已从简单的HTML DOM解析器中生成。如果我打印_r $ dataarray,我将获得以下输出
Array (
[0] => Array ( )
[1] => Array (
[0] => 'value1a'
[1] => 80
[2] => '2016-06-14 16:40:51'
[3] => )
[2] => Array (
[0] => 'value1b'
[1] => 80
[2] => '2016-06-14 16:30:17'
[3] => )
[3] => Array (
[0] => 'value1c'
[1] => 80
[2] => '2016-06-14 16:40:51'
[3] => )
)
和searchArray()是动态生成的,如果我print_r the SearchArray()我会得到以下结果:
Array (
[0] => Array (
[0] => 'value1c'
[1] => 80
[2] => '2016-06-14 16:40:51'
[3] => )
)
我正在尝试将searcharray()与dataarray()匹配,并给出true的布尔结果,如果(所有3个值)searchAray()将(所有3个值)dataarray匹配()dataarray()
因此,在这种情况下,这将是一个真实的语句。
您需要编写自定义功能才能递归匹配数组。
您可以在下面的文章中检查解决方案,这将对您有很大帮助。
https://www.daniweb.com/programmming/web-development/threads/168654/compare-multi-dimensional-arsional-arrees-arrees-andares-and-rays-and-return-return-return-they-they-keys-who-s-values-who-s-values-aare-are-are-are-difuredent
您可以使用PHP函数array_search
(http://php.net/array_search),因为在测试搜索/键相等时,PHP将检查整个数组的内容以检查该数组他们是平等的。这是我的测试案例;
<?php
$dataArray = array(
array(),
array(
'value1a',
80,
'2016-06-14 16:40:51',
null
),
array(
'value1b',
80,
'2016-06-14 16:30:17',
null
),
array(
'value1c',
80,
'2016-06-14 16:40:51',
null
)
);
$searchArray = array(
'value1c',
80,
'2016-06-14 16:40:51',
null
);
var_dump(array_search($searchArray, $dataArray)); // int(3) (the found key)
$searchArray[0] = 'some other value';
var_dump(array_search($searchArray, $dataArray)); // false
?>