This post was very useful: MySQL integer field is returned as string in PHP
In my model, I have a result_array()
where I want one of the six elements in each 'row' (bookID
) to be an INT when it goes back to the controller. .
$bookList = $this->db->query('SELECT bookID....etc')->result_array();
My var_dump produces this..
1 =>
array (size=6)
'ownerID' => string '6' (length=1)
'bookID' => string '53' (length=2)
'address' => string '123 main road to wherever' (length=25)
'Company' => string 'xxxxxxxxxx xxxxxxxx' (length=18)
'FullName' => string 'John Smith' (length=10)
2 => ...etc...
3 => ...etc...
4 => ...etc...
1 =>
array (size=6)
'ownerID' => string '6' (length=1)
'bookID' => int 53
'address' => string '123 main road to wherever' (length=25)
'Company' => string 'xxxxxxxxxx xxxxxxxx' (length=18)
'FullName' => string 'John Smith' (length=10)
2 => ...etc...
3 => ...etc...
4 => ...etc...
What is the most efficient way of iterating through the result array, which could potentially have 1,000 rows, changing the second element from a string to an INT before returning the results to the calling function?
return $bookList;