"111", "key2" =>"222", "key3" =>"333", "key4"...">

Export array key and value as variable name and value

given this array:

$segments = array( "key1" =>"111", "key2" =>"222", "key3" =>"333", "key4" =>"444" ); 

I want to have the following data:

$key1 has the value "111";

$key2 has the value "222";

$key3 has the value "333";

$key4 has the value "444";

What can I do?

+6
source share
2 answers

PHP has a built-in function that does just that:

 extract($segments); 

http://php.net/manual/en/function.extract.php

+14
source

use

 extract($segments) 

Literature:

  • extract Extract the keys of the hash array into the appropriate variables
  • compact Do the opposite
+7
source

Source: https://habr.com/ru/post/898715/


All Articles