循环遍历php中的json对象。 [英] Loop through json object in php.
本文介绍了循环遍历php中的json对象。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我跟随json对象,我想在其中添加'quantity'字段。我的代码是:
I've following json object and I want to make addition of 'quantity' field in it. My code is:
while($row=mysql_fetch_array($result)){
$posts = json_decode($row['value'],true);
array_push($response,$posts);
}
//print_r($response);
foreach($response as $value){
//$plus +=1;
$plus = $plus+$value['quantity'];
}
print_r($ response)=
print_r($response)=
Array
(
[0] => Array
(
[0] => Array
(
[srno] => 1
[name] => Gaspari Aminolast
[quantity] => 2
[price] => 2920.0000
[total_bill] => 5840
)
[1] => Array
(
[srno] => 2
[name] => Gaspari Amino Max
[quantity] => 2
[price] => 2640.0000
[total_bill] => 5280
)
[2] => Array
(
[srno] => 3
[name] => Myofusion 10Lbs
[quantity] => 2
[price] => 8400.0000
[total_bill] => 16800
)
)
[1] => Array
(
[0] => Array
(
[srno] => 1
[name] => Gaspari Aminolast
[quantity] => 2
[price] => 2920.0000
[total_bill] => 5840
)
[1] => Array
(
[srno] => 2
[name] => Gaspari Amino Max
[quantity] => 2
[price] => 2640.0000
[total_bill] => 5280
)
[2] => Array
(
[srno] => 3
[name] => Myofusion 10Lbs
[quantity] => 2
[price] => 8400.0000
[total_bill] => 16800
)
)
[2] => Array
(
[0] => Array
(
[srno] => 1
[name] => Gaspari Aminolast
[quantity] => 2
[price] => 2920.0000
[total_bill] => 5840
)
[1] => Array
(
[srno] => 2
[name] => Gaspari Amino Max
[quantity] => 2
[price] => 2640.0000
[total_bill] => 5280
)
)
[3] => Array
(
[0] => Array
(
[srno] => 1
[name] => Gaspari Aminolast
[quantity] => 2
[price] => 2920.0000
[total_bill] => 5840
)
[1] => Array
(
[srno] => 2
[name] => Gaspari Amino Max
[quantity] => 2
[price] => 2640.0000
[total_bill] => 5280
)
)
[4] => Array
(
)
[5] => Array
(
)
[6] => Array
(
[0] => Array
(
[srno] => 1
[name] => Gaspari Amino Max
[quantity] => 2
[price] => 2640.0000
[total_bill] => 5280
)
[1] => Array
(
[srno] => 2
[name] => Gaspari Aminolast
[quantity] => 2
[price] => 2920.0000
[total_bill] => 5840
)
)
)
这里我总是得到$ pluse = 0。我该怎么办。
Here I always get $pluse=0. What I should do.
推荐答案
row = mysql_fetch_array(
row=mysql_fetch_array(
result)){
result)){
帖子 = json_decode(
posts = json_decode(
这篇关于循环遍历php中的json对象。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文