0

This seems like a very basic question, but I just cannot figure it out. I am trying to parse through this array in a blade template.

I am saving data to a session variable that is an array. When I dd the variable in the view I get this...

"[["Less than $50,000","$50,000-$100,000","More than $100,000"],["Step2-option1","Step2-option2"],["Step3-option2"]]"

It looks like it's saving to the database as a string instead of an array. Is that correct? When I try to dd($variable[0]) I only get "[". If it is a string, I need to be saving it another way or at least taking this and converting it back to an array.

Each piece of this "array" is from a multi-step form that I am aggregating into a session variable using Session::push();

Thanks for your help!

8
  • How are you saving/storing the data? Show that part of your code. Commented Sep 28, 2018 at 12:44
  • Can you try json_decode first? then show us the new result. add true also as the 2nd parameter. Commented Sep 28, 2018 at 12:45
  • I don't know how it would work if you don't have escaped double quotes or used combination of single quotes/double quotes there. And secondly, we don't know your DB structure to help with insert. Commented Sep 28, 2018 at 12:48
  • 2
    Wow...json_decode was the way. I can't believe I didn't see that. Thanks, Vandolph! Feel free to submit that as an answer if you like and I'll check it. Commented Sep 28, 2018 at 12:50
  • 1
    Yes, please do! Commented Sep 28, 2018 at 12:52

1 Answer 1

2

Use json_decode, if still not working, try to add true in the 2nd parameter.

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.