function bar(): iterable {
return [1, 2, 3];
}
function gen(): iterable {
yield 1;
yield 2;
yield 3;
}
foreach (bar() as $value) {
echo $value; # => 123
}
PHP Types
Iterables
Null
$a = null;
$b = 'Hello php!';
echo $a ?? 'a is unset'; # => a is unset
echo $b ?? 'b is unset'; # => Hello php
$a = array();
$a == null # => true
$a === null # => false
is\_null($a) # => false
Float (Double)
$float1 = 1.234;
$float2 = 1.2e7;
$float3 = 7E-10;
$float4 = 1\_234.567; // as of PHP 7.4.0
var\_dump($float4); // float(1234.567)
$float5 = 1 + "10.5"; # => 11.5
$float6 = 1 + "-1.3e3"; # => -1299
Boolean
$boolean1 = true;
$boolean2 = TRUE;
$boolean3 = false;
$boolean4 = FALSE;
$boolean5 = (boolean) 1; # => true
$boolean6 = (boolean) 0; # => false
Boolean are case-insensitive
Comments