javascript - How to convert js nested object to php array
Get the solution ↓↓↓I am trying to convert js object in php array it is working but inside that object there are more objects which also need to convert in array
here is how i am converting
$data = json_decode($order->data,true);
dd($data);
result
array:12 [
"paymethod_id" => 1
"business_id" => 76
"delivery_type" => "1"
"driver_tip" => 0
"delivery_zone_id" => 6569
"delivery_datetime" => null
"location" => array:2 [
"lat" => 18.7675049
"lng" => -103.1445221
]
"deliveryOptionmodal" => array:3 [
"id" => 2
"value" => "Esperar en la entrada"
"$$hashKey" => "object:525"
]
"delivery_cost_new" => 20
"products" => "[{"id":48732,"code":"NPxRSw","quantity":1,"options":[],"ingredients":[]}]"
"customer_id" => 129731
"customer" => "{"id":129731,"name":"bil","middle_name":null,"lastname":"ar","second_lastname":null,"photo":null,"email":"[email protected]","cellphone":"0213123132131","address":"CoalcomГЎn, MichoacГЎn, Mexico","location":"{\"lat\":18.7675049,\"lng\":-103.1445221}","internal_number":null,"address_notes":"sss","zipcode":null,"map_data":{"library":"google","place_id":"ChIJz6WGrUw-MIQR_jYIoFZ-RPM"},"tag":"home"}"
]
You can see customer and product object is not converted into array how i can do that?
Answer
Solution:
In simple terms, you are sending anJSON
encoding of anJSON
object, with properties that are already encoded. You can send the correct data which is the correct solution, but sometimes wrong solutions needs to be made to fix existing problems.
Then just decode the properties and you should be fine.
$data = json_decode($order->data, true);
$data['products'] = json_decode($data['products'], true);
$data['customer'] = json_decode($data['customer'], true);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: trying to access array offset on value of type null
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.