2

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;
}

1 Answer 1

6

extract can do that for you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.