The problem is that when you unset() an element, the indexes are kept intact. In this case, index 1 no longer exists, so the array is converted to an object.
To make the array re-indexed sequentially, you can do something like this:
$numbers_db = '["1", "2", "3"]'; echo $numbers_db; $numbers= json_decode($numbers_db,true); //json decode numbers ar if (($key = array_search(2, $numbers)) !== false) { unset($numbers[$key]); $numbers = array_values($numbers); } $numbers_final = json_encode($numbers); echo $numbers_final;
source share