I'm working on a PHP application that queries MySQL using a database class. This link will take you to the class: real-world oop using PHP and MySQL:
The lesson should not be regarded as a modern reference because it illustrates numerous incorrect practices! I modified the class to better suit my needs, but there is a problem (maybe a stupid one). Using select(), a multidimensional array with three associative columns (id, first name, last name) each row is returned:
Array
(
[0] => Array
(
[id] => 1
[firstname] => Firstname one
[lastname] => Lastname one
)
[1] => Array
(
[id] => 2
[firstname] => Firstname two
[lastname] => Lastname two
)
[2] => Array
(
[id] => 3
[firstname] => Firstname three
[lastname] => Lastname three
)
)
Now I want to use MySQL fetch assoc() to use this array as a result. Although this is with simple/flat arrays, I am aware that it may be used with foreach(). I believe I must declare a new foreach() inside of each foreach(), however, I believe this may slow down or increase server load.
So, what is the simplest approach to use foreach() with this multidimensional array?