<?php
$array = array(
array('pear', 'apple'),
array('banana', 'coconut'),
'orange' // This is not an array element
);
foreach ($array as $value) {
// Check type of element...
if (is_array($value)) {
foreach ($value as $fruit) {
echo $fruit . PHP_EOL;
}
} else {
echo $value . PHP_EOL;
}
}
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/8qFuC on line 14
pearPHP_EOL
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/8qFuC on line 14
applePHP_EOL
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/8qFuC on line 14
bananaPHP_EOL
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/8qFuC on line 14
coconutPHP_EOL
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/8qFuC on line 17
orangePHP_EOL