hello forums!!
Can anybody suggest in the following case:
How to remove an element from an index array and reseting its indexes?
Example:

$array = array('x', 'y', 'z',..);
unset($array[1]);
print_r($array); // results: 0 => x, 2 => z ,which doesn't reset the indexes
// I would like to have the result as : 0 => x, 1 => z , ie rearraning the indexes

How to accomplish this ?
Thanks in advance for the suggestions.

    You can accomplish that with sort function:
    sort($array) after unset.

      Of course, you could also ask yourself the question: does it matter? If you cycle through the resulting array via a foreach() loop, it doesn't matter whether the indexes are sequential or not. I'm not saying there's never a reason to worry about it, just suggesting you consider whether it's necessary before adding the extra code.

        Write a Reply...