1

I have an string array structured like this:

[
    [
    //Amount of elements can vary
    "item",
    "item",
    "item"
    ],
    [
    //Amount of elements can vary
    "item", 
    "item", 
        //Amount of these nested arrays can vary
        [
            "item",
            11
        ], 
        [
            "item",
            11
        ],
    "item",
    "time"
    ]
]

I tried casting the string variable with (array) but to avail. I have no idea how to get php to read it as an array. I also exploded the "[" and cast each element in that array to (array). That improved the situation but it was still unusable.

2
  • Where are you getting your string from? Commented Feb 17, 2014 at 4:38
  • I am getting it from a database that I can't change the structure of it. That string is what I have to make do with. Commented Feb 17, 2014 at 4:39

1 Answer 1

4

How about simply...

$array = json_decode($string, true);

works for me - http://ideone.com/DxAeHt

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

1 Comment

Thanks for the quick answer! I glazed over that when reading the php documentation, will mark as answer. :D

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.