1

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

2
  • 1
    When I run your code here 3v4l.org/jBrOo it works fine. Maybe make sure that $arr is really an array before your echo Commented Apr 18, 2022 at 10:18
  • 1
    Hi, Eddy. Thanks for your prompt reply. You are right. I have found the issue. See my answer below. It was my bad that I only inserted JSON data in one row but decoding for every rows in the table. I should have checked the data-table before running the code. Commented Apr 18, 2022 at 10:22

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.