-3
employees = [
    {
    "firstName":"John",
    "lastName":"Doe",
    "sub":[{"sub_name":"subcat1"},
           {"sub_name":"subcat2"}
    ]
    }, 
    {
    "firstName":"Anna",
    "lastName":"Smith",
    "sub":[{"sub_name":"subcat3"},
           {"sub_name":"subcat4"}
    },
    {
    "firstName":"Peter",
    "lastName":"Jones",
    "sub":[{"sub_name":"subcat5"},
           {"sub_name":"subcat6"}
    },
];

I want to construct a multidimensional array which after ecoding using json_encode() function in php should give me the output in above mentioned json format.

How the multidimensional array should look like?

2
  • 2
    Have you tried anything? Commented Sep 15, 2014 at 11:26
  • So, the problem is actually you don't know how to build your array in first place? Take a look at that Commented Sep 15, 2014 at 11:31

1 Answer 1

1

To work backwards from the json you've got, run var_export(json_decode($json, true)) and take a look at the array it gives you.

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.