1

I have a function without arguments and want to get arguments name and value from variable when call function

 $name   = "ali";
 $family = "smith";

 function info(){
  print_r(func_get_args);
}

 info($name,$family); //array("name"=>"ali","family"=>"smith")

But in this case get me numeric keys array with values I don't want use compact function and read this link but args_with_keys not correct work and get me numeric array

Ali smith
  • 31
  • 6
  • 1
    Possible duplicate of [original variable name passed to function?](https://stackoverflow.com/questions/4503443/original-variable-name-passed-to-function) – Script47 Sep 02 '19 at 08:47
  • 1
    The actual dupe (not dupe of dupe): https://stackoverflow.com/questions/255312/how-to-get-a-variable-name-as-a-string-in-php – Script47 Sep 02 '19 at 08:47
  • What about just using an array? – Brett Gregson Sep 02 '19 at 08:48
  • maybe helpful - https://stackoverflow.com/questions/19126860/named-function-parameters-in-php – splash58 Sep 02 '19 at 09:12
  • @Ali I can't imagine wanting to craft a function where there is no control over the incoming parameters, but if you want a fully dynamic payload to be passed in, just pass in an associative array. Of course, you won't have any control over the data types within that array, so that is a drawback. More cleanly, I would try to refactor your task to use [PHP8's named parameters](https://stackoverflow.com/a/64997399/2943403). – mickmackusa Aug 22 '23 at 21:48

0 Answers0