There is an array $aa and the data in it is like this: [{goodid:270,num:1},{goodid:277,num:5}] I want to extract the values in goodid: 270 and 277. Write? Tried: foreach((array)$aa as $v){echo $v['goodid'];]} error.... I am a primary school student who has just started, please help and guide me, thank you very much?
First determine {goodid:270,num:1}. This is not a correct type in php, but it is correct in js.
$arr = [ "{'goodid':270, 'num':1}", "{'goodid':277,'num':5}",];$newarray = [];foreach ($arr as $value){ $value = json_decode($value,true ); $newarray[] = $value['goodid'];}print_r($newarray);
First of all, arrays and objects in php are completely separated, you can solve it on the front end
Masters passing by, please help me take a look~Thank you very much? ? ?