有一個陣列$aa 然後裡面的資料是這樣的:[ {goodid:270,num:1},{goodid:277,num:5} ] 我想提取goodid裡的值:270和277該怎麼寫?試過:foreach((array)$aa as $v){echo $v['goodid'];]}出錯....小弟是剛入門的小學生,請大神們幫忙指導一下,萬分感謝?
首先確定{goodid:270,num:1},在php中這不是一個正確的型,在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);
首先php中陣列與物件是完全分開的, 你可以在前端就解決了
var arr = [{ goodid: 270, num: 1 }, { goodid: 277, num: 5 }]; let newArr = []; for (let index in arr) { newArr[index] = arr[index]['goodid']; }; console.log(newArr);
路過的大神們,幫忙看一下~萬分感謝? ? ?
首先確定{goodid:270,num:1},在php中這不是一個正確的型,在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);
首先php中陣列與物件是完全分開的, 你可以在前端就解決了
路過的大神們,幫忙看一下~萬分感謝? ? ?