1<?php
2
3// numeric array keys with no gaps
4$a = ['a', 'b', 'c'];
5echo json_encode($a);
6// ["a","b","c"]
7
8// filter out the 'b' element to introduce a gap in the keys
9$a = array_filter($a, function ($v) {
10 return $v !== 'b';
11});
12echo json_encode($a);
13// {"0":"a","2":"c"}
14
15// re-index the array to remove gaps
16$a = array_values($a);
17echo json_encode($a);
18// ["a","c"]