-
Notifications
You must be signed in to change notification settings - Fork 0
/
foreach.php
30 lines (27 loc) · 867 Bytes
/
foreach.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
$things = array('Sgt. Pepper', "11", null, array(1,2,3), 3.14, 12 + 7, false, (string) 11);
foreach($things as $element){
if(is_integer($element)){
echo "$element is an integer ";
} elseif(is_float($element)){
echo "$element is a float ";
} elseif(is_bool($element)){
echo "$element is a boolean ";
} elseif(is_array($element)){
echo "\$element is an array, whose elements are: ".implode($element, ", ").PHP_EOL;
// Or instead of .implode(), you can use a nested foreach loop:
// foreach($element as $innerArray){
// echo $innerArray.PHP_EOL;
// }
} elseif (is_null($element)){
echo "$element is null ";
} elseif(is_string($element)){
echo "$element is a string ";
}
if(is_scalar($element)){
echo "and is also scalar.\n";
} else {
echo "and is also a non-scalar element of this array.\n";
}
}
?>