I was wondering. I always do fetch and then create variables when I do loop. Is there a way to do this more efficient? Like as in automatically?
Maybe something like convert_to_variable("name","description","etc") and it'll automatically set variables for me without having to do each manually? Or maybe a single command like convert_to_variable($rows) and it'll do the rest for me.
Here is what I am doing now.
$sql = "SELECT * from projects";
$rows = $db->fetch_all_array($sql);
foreach($rows as $row) {
$name = $row['name'];
$description = $row['description'];
}
Something easier would be
$sql = "SELECT * from projects";
$rows = $开发者_如何学运维db->fetch_all_array($sql);
foreach($rows as $row) {
convert_to_variable($row);
echo $name, $description;
}
extract can do that for you.
精彩评论