Last active
June 1, 2024 06:42
-
-
Save Kcko/3c5dbbd655bfe2c41018bddfd933ea83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// rest ... a,b,c,d,e => [] | |
function concatenate($transform, ...$strings) { | |
$string = ''; | |
foreach($strings as $piece) { | |
$string .= $piece; | |
} | |
return($transform($string)); | |
} | |
echo concatenate("strtoupper", "I'm ", 20 + 2, " years", " old."); // I'M 22 YEARS OLD. | |
// spread ... [] | |
function add($a, $b, $c) { | |
return $a + $b + $c; | |
} | |
$operators = [2, 3]; | |
echo add(1, ...$operators); // 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment