duanleiliu7373 2017-02-14 03:30
浏览 73
已采纳

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

Here is my array:

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

how can i assign each value a key variable? for example,

$key = $value

so in this case, it would be:

$username = 'john';
$email = 'johnbobby123@gmail.com';
etc...
  • 写回答

1条回答 默认 最新

  • douyue1998 2017-02-14 03:34
    关注

    Possibly you need php.extract: http://php.net/manual/en/function.extract.php

    $array = ['username' => 'John', ...];
    extract($array);
    echo $username; // John
    
    otherwise just echo $array['username'] // John
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?