我删除了旧帖子以使这一点更清楚。我有 2 个数组需要比较和匹配,但前提是每个数组的 2 个值相同。
$array1 = $plugins
$array2 = $xml_dump
两个数组的示例:
$plugins
Array
(
[all] => Array
(
[ajax-category-dropdown/dhat-ajax-cat-dropdown.php] => Array
(
[Name] => Ajax Category Dropdown
[PluginURI] => http://www.example.com/ajax/
[Version] => 0.1.5
[Description] => Generates multi-level ajax.
[Author] => DyasonHat
[AuthorURI] => http://www.dyasonhat.com
[Title] => Ajax Category Dropdown
[AuthorName] => Dya
)
[akismet/akismet.php] => Array
(
[Name] => Akismet
[PluginURI] => http://akismet.com/
[Version] => 2.5.3
[Description] => Used by millions
[Author] => Automattic
[AuthorURI] => http://automattic.com/
[Title] => Akismet
[AuthorName] => Automattic
)
$xml_dump
SimpleXMLElement Object
(
[plugin] => Array
(
[0] => SimpleXMLElement Object
(
[name] => Ajax Category Dropdown
[ex_version] => 0.1.5
[ex_date] => 2008-01-03
[plugin_url] => http://wordpress.org/extend/plugins/wp-contactform/
[advisory_url] => http://osvdb.org/show/osvdb/43284
)
[1] => SimpleXMLElement Object
(
[name] => WP-ContactForm
[ex_version] => 2.0.7
[ex_date] => 2008-01-03
[plugin_url] => http://wordpress.org/extend/plugins/wp-contactform/
[advisory_url] => http://osvdb.org/show/osvdb/43284
)
[2] => SimpleXMLElement Object
(
[name] => Math Comment Spam Protection
[ex_version] => 2.1
[ex_date] => 2008-01-03
[plugin_url] => http://wordpress.org/extend/plugins/math-comment-spam-protection/
[advisory_url] => a
)
只有当 $array1 Name
, Version
与 $array2 name
, 匹配时,我才需要它返回值(或返回 true) >ex_version
在上面的例子中你可以看到
$array1
Name => Ajax Category Dropdown
Version => 0.1.5
///has a match in
$array2
name => Ajax Category Dropdown
ex_version => 0.1.5
我尝试了 array_intersect
的多种变体,但我无法让它为每个数组匹配 2 个值。
最佳答案
如果我理解正确,应该这样做:
array_intersect_assoc(array_intersect($global_plugins, $xml_plugins), array_intersect($plugin_verso, $xml_plugin_version));
你的问题很困惑,你在谈论 $array1
和 $array2
但我看到了其中四个!
无论如何,您是否尝试过以下方法?这只是一个大胆的猜测,但是......
$result = array_intersect($global_plugins, $xml_plugins, $xml_plugin_version, $plugin_verso);
如果这不起作用,我建议您放弃现实世界的数组并创建一些简单/小的虚拟数组,并向我们提供您想要为完全相同的虚拟数据存档的结果。
关于php - 比较 2 个数组 Php 中的 2 个数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5821234/