This is based on a previous question I asked.
Lets say I have run an SQL query and received the following into a variable $res:
name | language
-------------------------
bob | English
bob | Dutch
Sally | English
Sally | Spanish
Sally | German
i.e. $res["name"] currently equals the first column etc.
Is there a PHP function or sequence of functions (without writing a loop) to turn $res into a map so that I could write $res["bob"] and receive an array ["English", "Dutch"] or $res["Sally"] and receive ["English", "Spanish", "German"]?
$map = array();
foreach ($mysqlResult as $row) {
$map[$row['name']][] = $row['language'];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With