php json encode remove array index

Solutions on MaxInterview for php json encode remove array index by the best coders in the world

showing results for - "php json encode remove array index"
Klara
05 May 2018
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"]
Souleymane
18 Mar 2019
1$arr['dates'] = array_values($arr['dates']);
2//..
3$arr = json_encode($arr);
4