How to skip the 1st element in an array loop with PHP

2 Answers

0 votes
$array = [1, 2, 3, 4, 5, 6];

// Use array_slice to skip the first element
$modifiedArray = array_slice($array, 1);

// Iterate over the modified array
foreach ($modifiedArray as $value) {
    echo $value . "\n";
}


  
/*
run:
      
2
3
4
5
6

*/

 



answered Mar 31, 2025 by avibootz
0 votes
$array = ['a' => "PHP", 'b' => "Java", 'c' => "Python", 'd' => "C#", 'e' => 'C'];

// Use array_slice to skip the first element
$modifiedArray = array_slice($array, 1);

// Iterate over the modified array
foreach($modifiedArray as $key => $value) {
    echo "$key - $value\n";
}


  
/*
run:
      
b - Java
c - Python
d - C#
e - C

*/
 

 



answered Mar 31, 2025 by avibootz
...