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));