我删除了旧帖子以使其更加清楚。我有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 NameVersion与$ array2 nameex_version匹配时,我才需要它返回值(或返回true)

在上面的示例中,您可以看到
$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/

10-14 19:52