0

DETAILS

I am getting the following json data back via an ajax response.

"result":[{"word":"jquery","wordID":"1"},{"word":"github","wordID":"2"}]

I am trying to understand the information I've received (arrays confuse me). To do that I am trying to recreate the structure of the array in php.

If I were to recreate the array above would I write it like this?

$result=Array (
    [0] => Array (
        word => jquery
        wordID => 1        
    ) 
    [1] => Array (
        word => github
        wordID => 2 
    ) 

If no, how would I write it? Thanks.

2 Answers 2

1

use json_decode to convert json in an array , and then do a var_dump to see if the structure is what you need

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

2 Comments

I've chosen your answer as the answer because it best helped me examine the structure of the data I was trying to understand. Thanks :)
anytime :) glad that I could help
1

JSON is essentially the right-hand side of an assignment operation in Javascript, e.g.

var foo = [1,2,3];
          ^^^^^^^--- basically json

Your snippet above is, however, NOT valid json. You've got an object, which cannot simply show up as

"key":"value"

it has to be

{"key":"value"}

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.