0

To Clarify I used JSON.stringify(myArray) from view before I sent it to controller.

I have string array like following :

[
                [["\"1\"","\"1\""],["\"a\"","\"a\""]],
                [["\"2\"","\"2\""],["\"b\"","\"b\""],["\"c\"","\"c\""]],
                []
]

I want to fetch data by using foreach.

Like :

0- 1, 1 and a,a 
1- 2,2 and b,b and c,c 
2- null

I tried string_data[0][0] , it doesn't work.

And

foreach(string_data[0] as $value){
}

It also doesn't work.

Only string_data[0] works.

7
  • 1
    please make it more clear. the above string looks more like an array. Commented Mar 8, 2018 at 5:05
  • you can not use string in foreach Commented Mar 8, 2018 at 5:05
  • try regex : stackoverflow.com/questions/4345621/… Commented Mar 8, 2018 at 5:05
  • 1
    Is this string or json? Commented Mar 8, 2018 at 5:05
  • 1
    Ok now you should use json_decode(VARIABLE, true) to convert json to a PHP array. Commented Mar 8, 2018 at 5:09

1 Answer 1

1

Solution is :

json_decode(VARIABLE, true)

Coz it(array) was sent from view as json.Stringfy. Php json decode function make it array again.

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

3 Comments

Welcome to StackOverflow. Answers with only code in them tend to get flagged for deletion as they are "low quality". Please read the help section on answering questions then consider adding some commentary to your Answer.
Why is that the answer? What does it do? What is the meaning of the second parameter?
explanation given

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.