PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

How do I remove an element from an array without changing the index values for the rest of the array?


If you want to completely remove a value from an array, then you should unset it.

For instance, if you create an array of the numbers from A - Z then the index values are 0 - 25.

If you then unset the value at index 2 (C) then the rest of the array keeps its index - value correlation intact.

<?php
$letters 
range("A","Z");
unset(
$letters[2));
print_r($letters);
?>


Copy and paste that to see the results... if that wasn't the question you were asking then please re-post with more explicit details of what you're looking for.



More arrays PHP Questions

How do I reverse sort the members of an array?
How can I reverse sort an array keeping the correlation between the index and value?
How do I return all the values in an array?
How can I check if a value is already in an array?
How do I remove and view the last element of an array?