Array to named variables

后端 未结 3 1383
北海茫月
北海茫月 2021-01-28 19:51

How can I take: $userarray (which is an array and I know holds 3 values) and put them into 3 seperate variables instead of looping through. There seperated by

3条回答
  •  温柔的废话
    2021-01-28 20:32

    I think you may be looking for either the list() or extract() functionality:

    list()

    list($userfield1, $userfield2, $userfield3) = $userarray;
    

    http://php.net/list

    extract()

    extract($userarray); // uses the array keys for variable names
    

    http://php.net/extract

提交回复
热议问题