php - "Same" syntax, different results using mysqli fetch_assoc()? -
so, not problem need solving, rather question out of curiosity , want of clarification. struggling piece of php/mysqli , while debugging , splitting code discovered code working, not way wrote it.
initial code (not working)
$result = $mysqli -> query("select nick userdata id=".$_session['uid']); // ... error checking here ... for($i = $result -> num_rows - 1; $i >= 0; $i--){ $result -> data_seek($i); $nick = ($result -> fetch_assoc())['nick']; // crash }
final code (working)
$result = $mysqli -> query("select nick userdata id=".$_session['uid']); // ... error checking here ... for($i = $result -> num_rows - 1; $i >= 0; $i--){ $result -> data_seek($i); $row = $result -> fetch_assoc(); // working $nick = $row['nick']; // working }
so, can enlighten me why first code breaks me?
best regards.
php 5.4 (2012-03-01) , later versions support array dereferencing function call.
see http://php.net/manual/en/language.types.array.php
as of php 5.4 possible array dereference result of function or method call directly. before possible using temporary variable.
as of php 5.5 possible array dereference array literal.
then shows examples. see example #7 on page.
Comments
Post a Comment