Thank you very much for your help!
夜夜**
夜夜** 2021-01-26 19:30:34
0
4
1143

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?

夜夜**
夜夜**

reply all(3)
沐雨轩

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

 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);
  • reply What does the master mean? Is it difficult to write back-end PHP? I need to change my thinking and change the front-end, or what? The following is the code. Please help me take a look at it. Thank you very much @! [The roughly brief code of the front end] is as follows: 1: this.selectedList.push({ good_id:this.cartList[index].goodid, num:this.cartList[index].sp_shuliang,good_jiage:this.cartList[index].sp_jiage }); 2: var canshu={good_xinxi:JSON.stringify(there.selectedList)}; await this.axios({ method: 'POST', url: '/php_api/wxpay/gwche_Dopay.php?ask=Doshouyin', data:canshu }).then(res => { console.log(res); }) ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// ///////////// [Backend PHP] Tried methods: 1: $aa=$_POST['good_xinxi']; foreach( (array)$aa as $v){ echo $v['good_id']} ///////////////////////////////////////////////////// /////////////////////// 2: $aa=$_POST['good_xinxi']; $bb=array_column( (array)$aa,'good_id') echo $bb; ///////////////////////////////////////////////////// ////////////////////// 3: $aa=$_POST['good_xinxi']; foreach( (array)$aa as $v){ echo $v->good_id; } ///////////////////////////////////////////////////// ///////////////////////////// [None of the above methods work] Tried printing: var_dump($_POST['good_xinxi']); [The result is OK] as follows: data: "string(87) "[{"good_id":276,"num":1,"good_jiage":"0.3"},{"good_id":277,"num":1,"good_jiage":"0.1 "}]"↵" errMsg: "request:ok" header: {Server: "nginx/1.15.11", Date: "Wed, 27 Jan 2021 10:09:27 GMT", Content-Type: "application/json", Transfer-Encoding: "chunked", Connection: " keep-alive", …} statusCode: 200 __proto__: Object
    移动用户-7223446 author 2021-01-27 18:33:53
夜夜裸奔

Masters passing by, please help me take a look~Thank you very much? ? ?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template