John Davidson

how to remove index in php response

0 comments
Message:


I've a variable $response which is an array and contains the below response


"example": {
"1": {
"name": "stan",
"city": "NY"
},
"2": {
"name": "wilson",
"city": "FL"
}
}

How can I remove the indexing from the response?



My Answer:
If you want to remove an index from an array in PHP, you can use the `unset()` function. Here's an example of how you can remove a specific index from your `$response` array:

php
// Your original response array
$response = array(
'index1' => 'value1',
'index2' => 'value2',
'index3' => 'value3'
);

// Remove index2 from the response array
unset($response['index2']);

// Output the modified response array
print_r($response);


After running this code, the output will be:


Array
(
[index1] => value1
[index3] => value3
)


As you can see, the 'index2' key has been removed from the `$response` array.

Rate this post

5 of 5 based on 1899 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us