fork download
  1. <?php
  2.  
  3. function exemplo(array $args) {
  4. $pares = array('par1' => 1, 'par2' => 2);
  5. $args = array_merge($pares, array_intersect_key($args, $pares));
  6. list($par1, $par2) = array_values($args);
  7.  
  8. return $par1 .' - '. $par2;
  9.  
  10. }
  11.  
  12. echo exemplo([]) . "\n"; // 1 - 2
  13. echo exemplo(['par1' => 3]) . "\n"; // 3 - 2
  14. echo exemplo(['par1' => 3, 'par2' => 4]) . "\n"; // 3 - 4
  15. echo exemplo(['par2' => 4]) . "\n"; // 1 - 4
Success #stdin #stdout 0.01s 24448KB
stdin
Standard input is empty
stdout
1 - 2
3 - 2
3 - 4
1 - 4