Which method is good to get values from array using 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 pros and cons of these methods. or any other method exists.
Thanks
extract()should be used with most care. But it is perfectly fine if you want to get a limited set of known variables from an associative array.list()however is usually unsuited for associative arrays. It’s for numerically indexed arrays, and assigns them to local variables.list()is sort of equivalent toextract(array_combine($list_keys, $array_values));Finally the normal array access, most common and most advisable if you only need to access a few array entries. Very obviously also preferred most everywhere because it leads to the least conflicts with existing local variables.