echo foreach code example
Example 1: php foreach
<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
foreach($age as $x => $val) {
echo "$x = $val<br>";
}
?>
Example 2: php foreach
$arr = ['Item 1', 'Item 2', 'Item 3'];
foreach ($arr as $item) {
var_dump($item);
}
Example 3: php array loop
foreach($array as $item) {
echo $item['filename'];
echo $item['filepath'];
echo '<pre>'; var_dump($item);
}
Example 4: echo foreach
foreach ($array as $element) {
echo "<a href='show_cls_db.php?id=" . implode('', $array2) . "'>{$element}</a><br/>";
}
Example 5: echo foreach
$array = array();
$result = mysql_query("SHOW TABLES FROM `st_db_1`");
while($row = mysql_fetch_row($result) ){
$result_tb = mysql_query("SELECT id FROM $row[0] LIMIT 1");
$row_tb=mysql_fetch_array($result_tb);
$array[] = $row[0];
$array2[] = $row_tb[0];
}
natsort($array);
natsort($array2);
foreach ($array as $item[0] ) {
echo "<a href=show_cls_db.php?id= foreach ($array2 as $item2[0]){echo \"$item2[0]\"}>{$item[0]}<br/><a/>" ;
}