Jump to content

Resetting Array Keys


ryanfait

Recommended Posts

Is there a function or simple way to reset the array keys?

 

For example convert the first array into the second.

 

Array
(
    [0] => apple
    [9] => banana
    [11] => orange
    [15] => pear
    [20] => strawberry
    [21] => mango
    [29] => raspberry
    [67] => apricot
)

 

to

 

Array
(
    [0] => apple
    [1] => banana
    [2] => orange
    [3] => pear
    [4] => strawberry
    [5] => mango
    [6] => raspberry
    [7] => apricot
)

 

Link to comment
https://forums.phpfreaks.com/topic/105880-resetting-array-keys/
Share on other sites

I think there is but I can't think of it right now this will due for you

<?php
function array_smoosh($array){
if(is_array($array)){
$data =array();
foreach($array as $value){
$data[] = $value;
}
return $array;
}
else{
return NULL;
}
}
#to use say
$new_array = array_smoosh($myarray);
?>

Link to comment
https://forums.phpfreaks.com/topic/105880-resetting-array-keys/#findComment-542634
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.