-1

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?

Steve Martin
  • 319
  • 2
  • 4
  • 10

2 Answers2

4

use array_values to reindex an array

$array = array_values($array);
castis
  • 8,154
  • 4
  • 41
  • 63
0

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);
wmfrancia
  • 1,176
  • 2
  • 10
  • 25