Php 从关联数组中获取键和值并指定变量
这是我的阵列:Php 从关联数组中获取键和值并指定变量,php,arrays,variables,key,associative-array,Php,Arrays,Variables,Key,Associative Array,这是我的阵列: Array ( [username] => john [email] => johnbobby123@gmail.com [first_name] => John [last_name] => Bobby) 如何为每个值分配一个关键变量?比如说, $key = $value 因此,在这种情况下,它将是: $username = 'john'; $email = 'johnbobby123@gmail.com'; etc... 您可能需要php.ext
Array ( [username] => john [email] => johnbobby123@gmail.com [first_name] => John [last_name] => Bobby)
如何为每个值分配一个关键变量?比如说,
$key = $value
因此,在这种情况下,它将是:
$username = 'john';
$email = 'johnbobby123@gmail.com';
etc...
您可能需要php.extract:
$array = ['username' => 'John', ...];
extract($array);
echo $username; // John
otherwise just echo $array['username'] // John