Reputation: 862
I insert PHP array to mySql using json_encode
method like this :
["11","10","4"]
Now I need to convert to php array:
$me = ["11","10","4"];
$you = json_decode($me, true);
echo $you;
But in result I see :
Warning: json_decode() expects parameter 1 to be string, array given in C:\xampp\htdocs\test\test.php on line 5
How do fix this?!
Upvotes: 1
Views: 3158
Reputation: 1703
Your problem is that $me
isn't a string. You should simply encapsulate it in single-quotes to change this.
$me = '["11","10","4"]';
$you = json_decode($me);
print_r($you); // becasue its now a PHP array,
// copy/paste will get you every time
Upvotes: 2