Jump to content
Larry Ullman's Book Forums

Data Types From Mysqli/php List


Recommended Posts

Hi Larry,

 

On page 493 you describe the list() function as well as its use in combination with a 'while' loop from a database select.  I have used this successfully innumerable times but I don't understand the following:

 

while(list($var1, var2, var3) = mysqli_fetch_row($result)) ....

 

The $var1, $var2 sources are in the database as tinyints, length 1. Yet if I do a vardump on the results of the list ($var1, $var2) they are strings, length 1.  Yet one can use those values as numeric array keys?

 

Can you please help me understand what's going on here?

 

Many thanks, and as always, Cheers from Oz.

Link to comment
Share on other sites

OK, I think that I understand what happens.

 

1) mysqli_fetch_row returns an array of strings - according to the w3schools manual which in my case get loaded into the PHP variables via the list.

2) in the php.net manual re arrays, it says "strings containing valid integers will be typecast to the integer type cast"

 

So while my MySQL data type is a tinyint, the mysqli_fetch_row returns its value as a string, but then that string is converted to an integer when it is inserted into an array as a key.

 

Please let me know if I've got it correctly.

 

Thanks.

Edited by Necuima
Link to comment
Share on other sites

  • 3 weeks later...
 Share

×
×
  • Create New...