4 ms·
You can get the best of both approaches in PHP 5.6 or later using the argument unpacking "..." operator that works similarly to the */"splat" operator in Python
by Lammy 6y ago
You can get the best of both approaches in PHP 5.6 or later using the argument unpacking "..." operator that works similarly to the */"splat" operator in Python or Ruby: https://www.php.net/manual/en/migration56.new-features.php https://www.php.net/manual/en/migration56.new-features.php
- gremlinsinc 6y agoit's not the best of both worlds though, splat should only be used on something where you're basically doing the same thing to a bunch of things. like add(1,2,3,4,5) -> function add(...$nums){ $count = 0; foreach($nums as $num) { $count += $num; } } If you know what arguments you're getting, then the more sound way would be just use an associative array, but either way you really don't get great type checking. This is a much better solution.