1

I want get name and value of function parameters by ..$arg or func_get_args()

I don't want use compact function and args_with_keys not correct work

I tried debug_backtrace()[0]['args'] and get_defined_vars() but It didn't work

 $color = 'blue';
 $size = '40cm';

 function data(){
 print_r(func_get_args());
 }

 data($color,$size); //array("color"=>"blue","size"=>"40cm")

OR

 $color = 'blue';
 $width = '40cm';
 $height = '50cm';

 function data(...$args){
      print_r($args);
 }

 data($color,$size); //array("color"=>"blue","width"=>"40cm","height"=>"50cm")

I tried this But get me numeric key of arguments but I want get parameters name and value like above example

Thank You

Ali smith
  • 31
  • 6
  • @nigel-ren I already read this link, and this link not answer me, I don't want use compact method and args_with_keys function get me numeric keys array – Ali smith Sep 02 '19 at 06:59
  • If you read the duplicate, you will notice that the accepted answer is that there is no way to do this directly. The other solutions are just work arounds. – Nigel Ren Sep 02 '19 at 08:58

0 Answers0