从关联数组中获取键和值并分配变量



这是我的数组:

Array ( [username] => john [email] => johnbobby123@gmail.com [first_name] => John [last_name] => Bobby)

如何为每个值分配一个键变量?例如,

$key = $value

所以在这种情况下,它将是:

$username = 'john';
$email = 'johnbobby123@gmail.com';
etc...

可能需要 php.extract: http://php.net/manual/en/function.extract.php

$array = ['username' => 'John', ...];
extract($array);
echo $username; // John
otherwise just echo $array['username'] // John

最新更新