Pros and cons of array extraction methods

Which method is good for getting values ​​from an array used in loops.

 1. list()
 2. extract()
 3. Normal extracting like $array['id']

code snippet:

$sel = mysql_query("SELECT id,name from user");
while($get = mysql_fetch_array($sel)){
 //Which one is good
 extract($get);  
 loop($id,$name)=$get;
 $id = $get['id'];
} 

I like to know the pros and cons of these methods. or any other method exists.

thank

+3
source share
2 answers

extract()Use with extreme caution. But this is great if you want to get a limited set of known variables from an associative array.

list()however, usually unsuitable for associative arrays. It is for numeric indexed arrays and assigns them to local variables. list()is kind of equivalentextract(array_combine($list_keys, $array_values));

, , , . , , .

+4

extract() , ( ). - , .

list() , list(), , , . , , .

+1

All Articles