Skip to main content
Rollback to Revision 2
Source Link
Giacomo1968
  • 25.3k
  • 11
  • 78
  • 106
$array = ["foo", "bar"]; foreach($array as $key => $value$key=>$value) { // $key = 0, $value = foo // On next iteration: $key = 1, $value =do barstuff } 

$key is the index of each $array itemelement

$array = ["foo", "bar"]; foreach($array as $key => $value) { // $key = 0, $value = foo // On next iteration: $key = 1, $value = bar } 

$key is the index of each $array item

foreach($array as $key=>$value) { // do stuff } 

$key is the index of each $array element

$array = ["foo", "bar"]; foreach($array as $key=>$value$key => $value) { // do$key stuff= 0, $value = foo  // On next iteration: $key = 1, $value = bar } 

$key is the index of each $array elementitem

foreach($array as $key=>$value) { // do stuff } 

$key is the index of each $array element

$array = ["foo", "bar"]; foreach($array as $key => $value) { // $key = 0, $value = foo  // On next iteration: $key = 1, $value = bar } 

$key is the index of each $array item

added 7 characters in body
Source Link
NikiC
  • 102.2k
  • 39
  • 194
  • 226
foreach($array as $key=>$value) {  //  do stuff } 

$key$key is the index of each $array$array element

foreach($array as $key=>$value) { //  do stuff } 

$key is the index of each $array element

foreach($array as $key=>$value) {  // do stuff } 

$key is the index of each $array element

Source Link
Owen
  • 84.8k
  • 21
  • 125
  • 116
Loading