当我wrong_predictions
var
$subject
得到print
时,我有一个echo $subject
[["2","subject2","0","0"],["4","ccd","50","5"]]
但是当我做echo gettype($subject)
时我得到string
因此,我无法使用foreach
loop
来遍历$subject
如何获取数组[["2","subject2","0","0"],["4","ccd","50","5"]]
格式的
答案 0 :(得分:1)
您可以使用json_decode
将该字符串转换为数组:
$subject = '[["2","subject2","0","0"],["4","ccd","50","5"]]';
print_r(json_decode($subject, true));
输出:
Array (
[0] => Array ( [0] => 2 [1] => subject2 [2] => 0 [3] => 0 )
[1] => Array ( [0] => 4 [1] => ccd [2] => 50 [3] => 5 )
)
答案 1 :(得分:0)
如@nick所述,请使用json_decode函数将其设置为数组。
$subject = '[["2","subject2","0","0"],["4","ccd","50","5"]]';
$stringToArray = json_decode($subject, true);
foreach($stringToArray as $key => $value){
print_r($value);echo '<hr>';
}