Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hello there, first of all I want to say I am a big fan of Larry Ullman's book. I used it to learn introductory PHP and now I am back learning advanced PHP. I am in chapter one working through the task list example. I have come across the following code:

while (list($task_id, $parent_id, $task) = mysqli_fetch_array ($r, MYSQLI_NUM)) {
  echo "<option value=\"$task_id\">$task</option>\n"; $tasks[] = array('task_id' => $task_id, 'parent_id' => $parent_id, 'task' => $task);
}

My question is - I thought I read somewhere that it is a bad practice to set a variable in a conditional statement, as in the case here where it is setting a list of variables to the values of an array. Is there any basis to this statement?

Link to comment
Share on other sites

Hello, and welcome to the forums.

 

Sometimes, you have to set variables in loops. There's just no other way around it.

I suppose it's always a best practice to keep loop computations to a minimum, but I've never heard of your bad practice.

Could you please provide a resource?

 

Thanks.

Link to comment
Share on other sites

Hello there, thanks for the response. I doubt it was even referring to PHP. I don't have a reference, it's just one of those things I remember reading somewhere and it remained in my head. I don't even know if it is from a reputable source, but I figure I'd post the question here and see your point of view.

Link to comment
Share on other sites

 Share

×
×
  • Create New...