Created
January 12, 2026 10:34
-
-
Save aleduca/70187f256d60212d00c10f0a5512cf41 to your computer and use it in GitHub Desktop.
Unpack example
This file contains hidden or 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 | |
| // COLOCA OS VALORES DO ARRAY ONDE EU USAR O ...$ARRAY | |
| function teste(int $num1, int $num2) | |
| { | |
| return $num1 + $num2; | |
| } | |
| $numbers = [1, 2]; | |
| // Fez o unpack dos valores do array $numers. | |
| echo teste(...$numbers); // retorna a soma de 1 + 2; | |
| $route = ['GET', [HomeController::class, 'index']]; | |
| // Fez o unpack dos valores do array $routes | |
| function route(string $httpMethod, array $controllerAndAction) | |
| { | |
| print_r($httpMethod); // GET | |
| print_r($controllerAndAction); // [HomeController,'index'] | |
| } | |
| route(...$route); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment