Adding to a multidimensional array in PHP
- by b. e. hollenbeck
I have an array being returned from the database that looks like so:
$data = array(201 => array('description' => blah, 'hours' => 0),
222 => array('description' => feh, 'hours' => 0);
In the next bit of code, I'm using a foreach and checking the for the key in another table. If the next query returns data, I want to update the 'hours' value in that key's array with a new hours value:
foreach ($data as $row => $value){
$query = $db->query($sql);
if ($result){
$value['hours'] = $result['hours'];
}
I've tried just about every combination of declarations for the foreach loop, but I keep getting the error that it's a non-object. Surely this is easier than my brain is perceiving it.