foreach loop in php
snippet in php

php loop through array

user2916

$clothes = array("hat","shoe","shirt");
foreach ($clothes as $item) {
	echo $item;
}

php loop

user2245


<?php 
for ($x = 0; $x <= 10; $x++)
{

   echo "The number is: $x <br>";
} 
?>  

forreah php

user7542

$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
    $value = $value * 2;
}

foreach loop array php

user6303

foreach (array as $value){ 
  //code to be executed; 
  print("value : $value");
} 

foreach (array as  $key => $value){ 
  //code to be executed; 
  print("key[$key] => $value");
} 

foreach loop in php

user5843

<?php
$arr = ['Item 1', 'Item 2', 'Item 3'];

foreach ($arr as $item) {
  var_dump($item);
}

$dict = array("key1"=>"35", "key2"=>"37", "key3"=>"43");

foreach($dict as $key => $val) {
  echo "$key = $val<br>";
}
?>

foreach in php

user6709

$arr = array(
	'key1' => 'val',
	'key2' => 'another',
	'another' => 'more stuff' 
);
foreach ($arr as $key => $val){
	//do stuff
}

//or alt syntax
foreach ($arr as $key => $val) :
   //do stuff here as well
endforeach;