fork download
  1. <?php
  2.  
  3. $a=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  4. $count = count($a);
  5.  
  6. for($i = 1; $i <= $count; $i += 2) {
  7. $new[] = ($a[$i]);
  8. }
  9.  
  10. print_r($a);
  11. echo PHP_EOL;
  12. print_r($new);
Success #stdin #stdout 0.03s 24040KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 6
    [6] => 7
    [7] => 8
    [8] => 9
    [9] => 10
)

Array
(
    [0] => 2
    [1] => 4
    [2] => 6
    [3] => 8
    [4] => 10
)