0

嗨,我有多维数组:

Array
(
    [0] => Array
        (
            [name] => uzsakymas
            [value] => title
        )

[1] => Array
    (
        [name] => preke
        [value] => name
    )

[2] => Array
    (
        [name] => kaina
        [value] => 5
    )

[3] => Array
    (
        [name] => kiekis
        [value] => 1
    )

[4] => Array
    (
        [name] => preke
        [value] => name2
    )

[5] => Array
    (
        [name] => kaina
        [value] => 5
    )

[6] => Array
    (
        [name] => kiekis
        [value] => 5
    )

)

但是当我尝试获取添加到 mysql 的值时,我得到了一个错误。我做错了什么?

$json = json_decode($_POST['json'], true);
print_r($json);
foreach($json as $key => $name) {
    echo $name['preke'];
}

未定义的索引:preke in...

4

2 回答 2

0

回声$name['preke'];不会让你走得很远。尝试$name['name'];name关键。

于 2012-07-12T22:37:56.240 回答
0

尝试:

$name['name'];

您的 $name var 是包含 2 个关联条目的数组: name , value;

于 2012-07-12T22:38:27.340 回答