Biske94 Posted February 13, 2018 Report Posted February 13, 2018 Hi i have encountered one quirk in PHP, and I was wandering if anyone can explain it to me. So writing this code gives me infinite loop public static function find_this_query($sql){ global $Database; $result_set = $Database->queryFunction($sql); $theObjectArray = array(); $var = $result_set->fetch_assoc(); // I put the whole array in $var while($row = $var){ // and then I put that here // some code here } return $theObjectArray; } Buuuut this doesnt public static function find_this_query($sql){ global $Database; $result_set = $Database->queryFunction($sql); $theObjectArray = array(); while($row = $result_set->fetch_assoc()){ // here I just put method and everything works fine // some code here } return $theObjectArray; } So I just wanna know why. Thanks nerdzzzz! Quote
administrator Posted February 14, 2018 Report Posted February 14, 2018 Because the $var variable in the first function (as it is written,) will always return true. S 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.