Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.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中合并四个多数组并存储在db中_Php_Mysql - Fatal编程技术网

在单数组php中合并四个多数组并存储在db中

在单数组php中合并四个多数组并存储在db中,php,mysql,Php,Mysql,我曾经这样做过:- [Attrdet] => Array ( [Color] => Array ( [0] => Purple [1] => Purple [2] => Purple [3] => Purple

我曾经这样做过:-

[Attrdet] => Array
        (
            [Color] => Array
                (
                    [0] => Purple
                    [1] => Purple
                    [2] => Purple
                    [3] => Purple
                    [4] => Purple
                    [5] => Purple
                    [6] => Pink
                    [7] => Pink
                    [8] => Pink
                    [9] => Pink
                    [10] => Pink
                    [11] => Pink
                )
        [Size] => Array
            (
                [0] => L
                [1] => S
                [2] => M
                [3] => XL
                [4] => XXL
                [5] => XXXL
                [6] => L
                [7] => S
                [8] => M
                [9] => XL
                [10] => XXL
                [11] => XXXL
            )

        [price] => Array
            (
                [0] => 100
                [1] => 200
                [2] => 300
                [3] => 400
                [4] => 500
                [5] => 600
                [6] => 700
                [7] => 800
                [8] => 900
                [9] => 1000
                [10] => 1100
                [11] => 1200
            )

        [quantity] => Array
            (
                [0] => 1
                [1] => 2
                [2] => 3
                [3] => 4
                [4] => 5
                [5] => 6
                [6] => 1
                [7] => 7
                [8] => 5
                [9] => 3
                [10] => 5
                [11] => 7
            )

    )
我想将其存储在db中,如下所示:- 紫色L 100 1 紫色S 200 2等等


它应该用这个数组的diff组合存储12条记录。我试过了,但没能成功。任何帮助都将不胜感激。

我不确定是否正确回答了您的问题,但假设每个描述符(颜色/大小/价格/数量)代表相同数量的商品,您可以执行以下操作:

$length = count($array['Attrdet']['Color']); //grab from either if all have the same length

for ($i = 0; $i < $length; $i++) {
    echo "Insert" .
            " color " . $array['Attrdet']['Color'][$i] . 
            " size " . $array['Attrdet']['Size'][$i] . 
            " price " . $array['Attrdet']['price'][$i] . 
            " quantity " . $array['Attrdet']['quantity'][$i] . "\n";
}
$length=count($array['Attrdet']['Color'])//如果所有长度相同,则从任一位置抓取
对于($i=0;$i<$length;$i++){
回显“插入”。
“颜色”。$array['Attrdet']['color'][$i]。
“大小”。$array['Attrdet']['size'][$i]。
“价格”。$array['Attrdet']['price'][$i]。
“数量”。$array['Attrdet']['quantity'][$i]。“\n”;
}

,不要试图将其转换为简单的INSERT语句,但请注意。确保使用准备好的语句来防止SQL注入!