Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

how to delete array element with shifting the indexes ?

9:24 am on Apr 22, 2008 (gmt 0)

5+ Year Member

hello forums!
Can anybody suggest in the following case:
How to remove an element from an index array and reseting its indexes?
[PHP]$array = array('x', 'y', 'z',..);
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[/PHP]
How to accomplish this ?
Thanks in advance for the suggestions.
10:12 am on Apr 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

You can add this line right after unset
$b = array_values($a);

...and test:

More about it here [php.net]

8:42 am on May 27, 2008 (gmt 0)

5+ Year Member


Featured Threads

Hot Threads This Week

Hot Threads This Month