$resultViewed='["88"]';
$viewed=json_decode($resultViewed);
if(!in_array("9",$viewed)){
print_r($viewed);
$viewed = array_push($viewed,"9");
print_r($viewed);
}
打印
Array ( [0] => 88 ) 2
而不是
Array ( [0] => 88,[1]=>9 )
该数组有效,但使用array_push()
添加其他值并不是我所期望的。
答案 0 :(得分:3)
删除作业:$viewed =
:
$viewed = array_push($viewed,"9");
只需:
array_push($viewed,"9");
它已经在manual,它会返回新的项目数,不数组的值。
或者只是使用简单的方法:
$viewed[] = "9";