homepage Welcome to WebmasterWorld Guest from 54.237.95.6
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
how to delete array element with shifting the indexes ?
PHPycho




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

hello forums!
Can anybody suggest in the following case:
How to remove an element from an index array and reseting its indexes?
Example:
[PHP]$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[/PHP]
How to accomplish this ?
Thanks in advance for the suggestions.

 

Habtom




msg:3632150
 10:12 am on Apr 22, 2008 (gmt 0)

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

...and test:
print_r($b)

More about it here [php.net]

xiongbin




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

array_splice($x,1,1);
print_r($x);

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved