foreach string php code example
Example 1: php foreach string char
$chars = str_split($str);
foreach($chars as $char)
{
}
Example 2: forreah php
$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
$value = $value * 2;
}
Example 3: foreach loop array php
foreach (array as $value){
print("value : $value");
}
foreach (array as $key => $value){
print("key[$key] => $value");
}
Example 4: foreach in php
$arr = array(
'key1' => 'val',
'key2' => 'another',
'another' => 'more stuff'
);
foreach ($arr as $key => $val){
}
foreach ($arr as $key => $val) :
endforeach;
Example 5: php ofreach
<?php
$a = array(1, 2, 3, 17);
foreach ($a as $index => $v) {
echo "Current value of \$a: $v.\n";
}
?>
Example 6: php foreach string in array
foreach($array as $item) {
echo $item['filename'];
echo $item['filepath'];
echo '<pre>'; var_dump($item);
}