Shaggy
0
Q:

php loop troug array

$clothes = array("hat","shoe","shirt");
foreach ($clothes as $item) {
	echo $item;
}
61
<?php
$salary[]=2000;
$salary[]=3000;
$salary[]=5000;

foreach($salary as $value){
  echo "Salary: $value<br>";
}
?>
4
$letters = ['a','b','c'];
foreach ($letters as $item) {
  echo $item;
}
1
foreach (array_expression as $value)
    statement
foreach (array_expression as $key => $value)
    statement
-1
<?php
$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
    $value = $value * 2;
}
// $arr is now array(2, 4, 6, 8)
unset($value); // break the reference with the last element
?>
1
foreach($array as $item=>$values){
     echo $values->filepath;
    }
0
foreach($array as $item) {
    echo $item['filename'];
    echo $item['filepath'];

    // to know what's in $item
    echo '<pre>'; var_dump($item);
}
0
foreach (array_expression as $value)
    statement
foreach (array_expression as $key => $value)
    statement
9
  Array ( 
    [0] => Array ( 
             [fid] => 14 
             [list] => 1 
             [data] => Array ( 
                         [alt] => 
                         [title] => 
                       )
             [uid] => 1 
             [filename] => trucks_10785.jpg 
             [filepath] => sites/default/files/trucks_10785.jpg 
             [filemime] => image/jpeg 
             [filesize] => 143648 
             [status] => 1 
             [timestamp] => 1291424171 
             [nid] => 8 
           ) 
    [1] => Array ( 
             [fid] => 19 
             [list] => 1 
             [data] => Array ( 
                         [alt] => 
                         [title] => 
                       ) 
             [uid] => 1 
             [filename] => school.jpg 
             [filepath] => sites/default/files/school.jpg 
             [filemime] => image/jpeg 
             [filesize] => 115355 
             [status] => 1 
             [timestamp] => 1292029563 
             [nid] => 8 
           ) 
    [2] => Array ( 
             [fid] => 20 
             [list] => 1 
             [data] => Array ( 
                         [alt] => 
                         [title] => 
                       )     
             [uid] => 1 
             [filename] => Life_is_wonderful_by_iNeedChemicalX.jpg 
             [filepath] => sites/default/files/Life_is_wonderful_by_iNeedChemicalX_0.jpg 
             [filemime] => image/jpeg 
             [filesize] => 82580 
             [status] => 1 
             [timestamp] => 1292029572 
             [nid] => 8 
           )
    [3] => Array ( 
             [fid] => 21 
             [list] => 1 
             [data] => Array ( 
                         [alt] => 
                         [title] => 
                       ) 
             [uid] => 1 
             [filename] => school_rural.jpg 
             [filepath] => sites/default/files/school_rural.jpg 
             [filemime] => image/jpeg 
             [filesize] => 375088 
             [status] => 1 
             [timestamp] => 1292029582 
             [nid] => 8 
           ) 
  ) 
0

New to Communities?

Join the community