how to remove array index from json in php

Solutions on MaxInterview for how to remove array index from json in php by the best coders in the world

showing results for - "how to remove array index from json in php"
Lucia
17 May 2020
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"]
queries leading to this page
how to delete object of json array in phpphp json encode remove array indexremove index from array php and convert array to json in phpremove data from json array phpremove json array from its postion in php php json array remove element php remove 5b 5d in json arrayjson remove element phplaravel json decode remove indexjson array remove index phpphp json encode remove keyhow to delete an object in a json array phpphp json remove array indexremove index numbers from json array phphow to remove array index from json in phpphp remove index from array json encoderemove object from json array phpremove apostrophe from json array phpremove array key in json phpremove index 0 1 from json array phpremove index in data json phpremove json array in phpremove all index from json in phphow to delete an object from a json array phpremove json from object in phphow to remove outer index from json using phphow to delete an object from an json array phphow to remove outer index from json in phphow to unset an object in a json array phpremove json from array phpphp remove key jsonphp json encode without keysremove array position php from jsonremove array from jscon encoderemove an element from json array phpremove index from json array phpspecific value remove from json array in phphow to remove outer index value in json using phpremove index key from json in phpremove index key from json phpconvert array into json in php remove array taghow to remove array index from json in php