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
547 Who developed the "avformat-59.dll" that comes with FFmpeg?
537 Uncaught (inpromise) Error on Electron: An object could not be cloned
709 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
548 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.