我使用json_encode
方法将PHP数组插入mySql,如下所示:
["11","10","4"]
现在我需要转换为php数组:
$me = ["11","10","4"];
$you = json_decode($me, true);
echo $you;
但结果我看到:
Warning: json_decode() expects parameter 1 to be string, array given in C:\xampp\htdocs\test\test.php on line 5
如何解决这个问题?!
答案 0 :(得分:2)
您的问题是$me
不是字符串。您只需将其封装在单引号中即可进行更改。
$me = '["11","10","4"]';
$you = json_decode($me);
print_r($you); // becasue its now a PHP array,
// copy/paste will get you every time