Jump to content

[SOLVED] Array Indexes


unkwntech

Recommended Posts

I should know this.

What is the easyest way to remove an item from an array and reset the indexes

 

I have

$array = array('1','2','3','4','5');
unset($array['3']);

Now i need the array to look like this after I do that:

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 5
)

Link to comment
https://forums.phpfreaks.com/topic/118468-solved-array-indexes/
Share on other sites

That's how you do it.  I just found the line on the manual:

 

Note: The unset() function allows removing keys from an array. Be aware that the array will not be reindexed. If a true "remove and shift" behavior is desired, the array can be reindexed using the array_values() function.

 

Under the Useful Functions section

;)

Link to comment
https://forums.phpfreaks.com/topic/118468-solved-array-indexes/#findComment-609860
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.