0

When I do var_dump($string); I get

string(894) "[{"id":"11","value":"Gotowy do u\u017cytku"},{"id":"12","value":"Na 4 k\u00f3\u0142kach"},{"id":"13","value":"20 minut - rozgrzany do pracy"},{"id":"14","value":"Pow. u\u017cytkowa 108 cm2"},{"id":"15","value":"Piec i grill w jednym"},{"id":"16","value":["tekst","\/images\/alfa\/domowa\/forninox\/1.jpg","lightbox"]},{"id":"17","value":["tekst","\/images\/alfa\/domowa\/forninox\/1.jpg","lightbox"]},{"id":"18","value":["tekst","\/images\/alfa\/domowa\/forninox\/3.jpg","lightbox"]},{"id":"19","value":["tekst","\/images\/alfa\/domowa\/forninox\/2.jpg","lightbox"]},{"id":"20","value":"cm 127"},{"id":"21","value":"cm 189"},{"id":"22","value":"cm2 108"},{"id":"23","value":"Kg 340"},{"id":"24","value":"\u00a6 cm 25\/20"},{"id":"25","value":"Mat. ceramiczny"},{"id":"26","value":"Stal nierdzewna"},{"id":"27","value":"W\u0142. ceramiczne"},{"id":"28","value":"min 20"},{"id":"29","value":"7"}]" 

and I what to put this string into array, so I do unserialize, like this:

$a = unserialize($string); 
var_dump($a);

But in the output I get:

bool(false) 

Enybody knows what I'm doing wrong?

2 Answers 2

4

You've got a json string. You want to use

$arr = json_decode($string, TRUE);

to deserialize it to an associative array.

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

8 Comments

Thank you very much, how did you recognize that is a json string?
Note this would not deserialize into an associate array, but rather a numerically indexed array. JSON has no concept of an associative array.
@MikeBrant php does have a concept of an associative array, though. If he used this solution, he could reference "tekst" by using $arr[5]["value"][0]. This key,value, dictionary-type referencing is the same as a php associative array.
@MikeBrant Here is the php reference to json_decode php.net/manual/en/function.json-decode.php
Yes, but truly this is a numerically indexed array of objects. The main enclosing array is a numerically indexed array not an associative array. You also cannot use ArrayAccess on the stdClass object that would be created for each value in the array. So your example would have to be $arr[5]->value[0]
|
0

It's not serialized, but json encoded. Use:

$decoded = json_decode($string);

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.