Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.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场景中,如何将数组元素从关联数组中逐个移动?_Php_Arrays_Associative Array_Array Key - Fatal编程技术网

在下面的PHP场景中,如何将数组元素从关联数组中逐个移动?

在下面的PHP场景中,如何将数组元素从关联数组中逐个移动?,php,arrays,associative-array,array-key,Php,Arrays,Associative Array,Array Key,我将以下关联数组命名为$\u POST,如下所示: Array ( [op] => add [product_id] => 12 [pack] => Array ( [1] => 1 ) [applicable_states] => Array ( [0] => multiselect-all [1] =>

我将以下关联数组命名为
$\u POST
,如下所示:

Array
(
    [op] => add
    [product_id] => 12
    [pack] => Array
        (
            [1] => 1
        )
    [applicable_states] => Array
        (
            [0] => multiselect-all
            [1] => 1
            [2] => 2
            [3] => 3
            [4] => 4
            [5] => 5
            [6] => 6
            [7] => 7
            [8] => 8
            [9] => 9
            [10] => 10            
        )

    [total_count] => 3000
)
现在您可以观察数组中的第一个键
$\u POST['applicative\u states']
它是
[0]=>multiselect all
。 在操作数组之前,我必须检查这个键。 每当此键出现在数组中时,我需要
$\u POST
数组,如下所示:

Array
(
    [op] => add
    [product_id] => 12
    [pack] => Array
        (
            [1] => 1
        )
    [applicable_states] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
            [3] => 4
            [4] => 5
            [5] => 6
            [6] => 7
            [7] => 8
            [8] => 9
            [9] => 10            
        )

    [total_count] => 3000
)

现在,您可以从上面的数组中看到,
[0]=>multiselect all
从新的结果数组中删除,并且每个数组值的位置都改变了一个。如何以最佳方式将我的
$\u POST
数组转换为上述结果数组?提前感谢。

您可能想看看数组\u shift()您可能想看看数组\u shift()您可能想看看数组\u shift()您可能想看看数组\u shift()您可能想看看数组
if (array_search('multiselect-all', $_POST['applicable_states']) === 0) 
    array_shift($_POST['applicable_states']);