Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
$a = array("pear","apple","apple","ball","cat"); $u = array_unique($a); echo json_encode($u);
输出显示为: {"0":"pear","1":"apple","3":"ball","4":"cat"}
我需要一个非关联数组作为输出:["apple","ball","cat","pear"]。
array_values在编码之前重新索引数组:
array_values
echo json_encode(array_values($u));