Search
 
SCRIPT & CODE EXAMPLE
 

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"]
Comment

PREVIOUS NEXT
Code Example
Php :: not get child all data in relationship with parent laravel eloquent 
Php :: laravel return validation errors 
Php :: php xml string 
Php :: php random 
Php :: php how to connect to db using PDO 
Php :: how to add custom field in comment form in wordpress 
Php :: array key value php 
Php :: check mobile or email in laravel 
Php :: Syntax error or access violation: 1071 La clé est trop longue. Longueur maximale: 1000" 
Php :: php multi condition if 
Php :: how to fetch data from url in php properly 
Php :: adeleye ayodeji 
Php :: php rand int 
Php :: yesterday php 
Php :: Unable to locate package php7.4 for kali 2021 
Php :: php call class method dynamically 
Php :: update profile method in laravel 
Php :: accessing json data in php 
Php :: php date in italiano 
Php :: date format with t and z php 
Php :: php function uppercase first letter 
Php :: removing index.php in codeigniter 
Php :: laravel collection has 
Php :: @foreac laravel 
Php :: get last element of array php 
Php :: autoload file laravel 
Php :: php lowercase assoc array 
Php :: php add array to array 
Php :: php foreach array pop 
Php :: laravel response json status 500 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =