Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

how to remove array index from json in php

<?php

// numeric array keys with no gaps
$a = ['a', 'b', 'c'];
echo json_encode($a);
// ["a","b","c"]

// filter out the 'b' element to introduce a gap in the keys
$a = array_filter($a, function ($v) {
    return $v !== 'b';
});
echo json_encode($a);
// {"0":"a","2":"c"}

// re-index the array to remove gaps
$a = array_values($a);
echo json_encode($a);
// ["a","c"]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #remove #array #index #json #php
ADD COMMENT
Topic
Name
6+1 =