简体   繁体   中英

Laravel- json_decode returns array but cannot echo array values in Laravel 9

So I have a Json data in my Database like below:-

$json = ["16502735051.jpg","16502735052.jpg","16502735053.jpg","16502735055.jpg"];

Now I decoded this JSON into an Array like below:-

$arr = json_decode($json);

when I print this arr using print_r it returns as below:-

Array ( [0] => 16502735051.jpg [1] => 16502735052.jpg [2] => 16502735053.jpg [3] => 16502735054.jpg [4] => 16502735055.jpg ) 

The prob occurs when I try to get the value from the array. I write this:-

echo $arr[0]

It return error. Shows:- Trying to access array offset on value of type null

I got the answer. It's not a bug or something. The problem was happening because, I have three rows in the DB table. Only one of them has Json Value. That's why other rows were returning null this Laravel returned Fatal error and stopped the script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM