What does splat operator between two integers mean?
As far as I know, the splat operator is used for passing the parameter on function. Manual.
An example :
<?php
function fx(...$a) {
print_r($a);
}
fx(1, 2, 3, 4, 5, 6); // array 1, 2, 3, 4, 5, 6
But what does it mean when the splat operator is between two integers like this?
<?php
echo 1...3; // Why is the output 10.3?
echo PHP_EOL;
echo 12...100; // Why is the output 120.1?
echo PHP_EOL;
... operator works only for unpacking traversable objects.
Your example uses . operator to concatenate two numbers interpreted as strings.
The following are equivalent:
echo 1...3; // interpreted as ((int) 1) . ((float) 0.3)
echo '1' . '0.3';
echo 12...100; // interpreted as ((int) 12) . ((float) 0.1)
echo '12' . '0.1';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With