There is an array called $parentArr.I want to get a specific array of JSONs out of it and make it an associative array, but it doesn't work.
print_r($parentArr);
Result ↓
Array
(
[id] = > 1
company_id = > 2
fruits=>{"apple":4"peach":2,"orange":1}
);
Take the fruits out of here and say $fruitArray=['apple'=>4,'peach'=>1,'orange'=>1].
$fruitArray=json_decode($parentArr["fruits", true);
print_r($fruitArray);
Results
Nothing is displayed.
php laravel
That's strange.I think the code below will work out as expected, so please compare the differences.
<?php
$json=json_encode(array("apple"=>4, "peach"=>2, "orange"=>1));
$parentArr=array("id"=>1, "company_id"=>2, "fruit"=>$json);
print_r($parentArr);
$fruitArray=json_decode($parentArr["fruits", true);
print_r($fruitArray);
Results
Array
(
[id]=>1
[company_id] = >2
[fruits]=>{"apple":4, "peach":2, "orange":1}
Array
(
[Apple]=>4
[peach]=>2
range=>1
© 2024 OneMinuteCode. All rights reserved.