-1

I've tried to refactor my code by using the list() php function but it returns null and I am not sure what I am not doing well. My code:

 public function test() {
      // content
      return ['variable' => $variable, 'variable1' => $variable1];
 }


 //
 list($variable, $variable1) = test();

I thought that's the way to use list(). Can someone give me a hint on what I am not doing alright?

IleNea
  • 569
  • 4
  • 17

1 Answers1

1

function list() is working for the numeric array only, in your case you should use extract() function

 function test() {
  return ['variable' => 11, 'variable1' => 12];
 }
 extract(test());
 echo $variable.'--'.$variable1;

Working example : https://3v4l.org/aVkpI

Rakesh Jakhar
  • 6,380
  • 2
  • 11
  • 20