I'm trying to create hash map or a 2d array using arrays in PHP. My values are hardcoded in, but this is what I currently have. I tried the code in the comments, but I realized that wasn't actually making a 2d array.
$hash_map = array();
$query = $this->students_m->getStudentClasses('2');
foreach ($query->result_array() as $key1=>$value1) {
$query2 = $this->students_m->getStudentsInfo('2', '10', '3');
foreach ($query2->result_array() as $key2=>$value2) {
/*
if (!in_array($value2['name'],$hash_map, true)) {
array_push($hash_map, $value2['name']);
}
*/
hash_map[$value1['id']][] = $value2['name'];
}
}
id and student_name are the names of the columns from the sql table. I ran this code and a couple variations of it:
foreach ($hash_map as $student) {
echo $student;
echo "<br>";
}
And I wasn't able to get the correct output. I'd like it so each value maps to an array of unique values, so an example of what I'm going for looks like:
hash_map['10'][0] = '123'
hash_map['10'][1] = '124'
hash_map['10'][2] = '125'
hash_map['3'][1] = '123'
hash_map['3'][2] = '128'
Is what I have close? Could someone help point me in the right direction?