Skip to content

Instantly share code, notes, and snippets.

@aleduca
Created January 12, 2026 10:34
Show Gist options
  • Select an option

  • Save aleduca/70187f256d60212d00c10f0a5512cf41 to your computer and use it in GitHub Desktop.

Select an option

Save aleduca/70187f256d60212d00c10f0a5512cf41 to your computer and use it in GitHub Desktop.
Unpack example
<?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