Question

I need to display array in sequence

my array

Array
(
 [0] => test@yahoo.com
 [1] => rans@yahoo.com
 [2] => maria@gmail.com
 [3] => lspap@gmail.com
 [6] => sage@yahoo.com
 [7] => rlope@hotmail.com
 [13] => alyssa@gmail.com
)

I want output like following

Array
(
 [0] => test@yahoo.com
 [1] => rans@yahoo.com
 [2] => maria@gmail.com
 [3] => lspap@gmail.com
 [4] => sage@yahoo.com
 [5] => rlope@hotmail.com
 [6] => alyssa@gmail.com
)

Now my question is how can display array like above sequence in PHP?

Was it helpful?

Solution

use array_values to reindex an array

$array = array_values($array);

OTHER TIPS

To display the values in sequence use a foreach loop as so

foreach($array as $arr){
 echo $arr."\n";
}

to store the values with new indexes or keys use

array_values($array);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top