Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:合并while循环+排序中的两个数组_Php_Arrays_Merge_While Loop - Fatal编程技术网

PHP:合并while循环+排序中的两个数组

PHP:合并while循环+排序中的两个数组,php,arrays,merge,while-loop,Php,Arrays,Merge,While Loop,在Wordpress中,每个WP_查询都会返回POST。在目前的情况下,我有两个职位 每个帖子都包含一些数组。因此,我得到了两个数组,我需要合并它们,以便稍后对它们进行排序。 所以现在如果我打印: echo "<pre>"; print_r($products_selected); echo "</pre>"; 阵列2: Array ( [0] => Array ( [0] => http://www.pag

在Wordpress中,每个WP_查询都会返回POST。在目前的情况下,我有两个职位 每个帖子都包含一些数组。因此,我得到了两个数组,我需要合并它们,以便稍后对它们进行排序。 所以现在如果我打印:

echo "<pre>";
print_r($products_selected);
echo "</pre>";
阵列2:

Array
(

    [0] => Array
        (
            [0] => http://www.page1.com
            [1] => Product 1
        )

    [1] => Array
        (
            [0] => http://www.page2.com
            [1] => Product 2

        )

    [2] => Array
        (
            [0] => http://www.page3.com
            [1] => Product 3
        )

    [3] => Array
        (
            [0] => http://www.page4.com
            [1] => Product 4

        )
    [4] => Array
        (
            [0] => http://www.page5.com
            [1] => Product 5

        )

)
如何合并它们,以便按产品名称排序[1]

例如:


您可以使用array\u merge\u递归$array1、$array2实现这个精确的结果,我将使用array\u merge和usort and。虽然如果你添加一些代码,也许我们可以将你的两个查询合并成一个。。。
Array
(

    [0] => Array
        (
            [0] => http://www.page3.com
            [1] => Product 3
        )

    [1] => Array
        (
            [0] => http://www.page4.com
            [1] => Product 4

        )
    [2] => Array
        (
            [0] => http://www.page5.com
            [1] => Product 5

        )

)
Array
(

    [0] => Array
        (
            [0] => http://www.page1.com
            [1] => Product 1
        )

    [1] => Array
        (
            [0] => http://www.page2.com
            [1] => Product 2

        )

    [2] => Array
        (
            [0] => http://www.page3.com
            [1] => Product 3
        )

    [3] => Array
        (
            [0] => http://www.page4.com
            [1] => Product 4

        )
    [4] => Array
        (
            [0] => http://www.page5.com
            [1] => Product 5

        )

)