6

Lord Google isn't giving me anything besides something about declaring optional variables with a value so they can be passed into the code without giving you an error. Is there even an equivalent of *Args or **kwargs in PHP?

Cheers

dreftymac
  • 31,404
  • 26
  • 119
  • 182
HayashiEsme
  • 303
  • 4
  • 9
  • PHP doesn't have anything for **kwargs AFAIK. but do your searches using the term 'associative arrays' that's what PHP folks call their dictionaries. – e4c5 Jan 05 '17 at 05:46
  • Briefly: `...$args` instead of `*args`. Neither variadic arguments nor argument unpacking have an equivalent for dictionaries/hash maps/associative arrays. See the [documentation](http://php.net/manual/en/migration56.new-features.php). – TigerhawkT3 Jan 05 '17 at 06:56

1 Answers1

2

For *Args I think you want this func_num_args() please refer to this link for more http://php.net/manual/en/function.func-num-args.php

For **kwargs This feature is not supported in php

justrohu
  • 595
  • 3
  • 9
  • 2
    The `...` splat has been around for over two years. It's probably more suitable, especially if the OP is more used to Python's equivalent operator. – TigerhawkT3 Jan 05 '17 at 06:58
  • If you're interested on how to make a function call passing kwargs from a dictionary, like `myfunction(**myargs)`, you can use [call_user_func_array](https://www.php.net/manual/function.call-user-func-array.php). – LRMAAX Oct 12 '19 at 22:48