Sijran :
My question is a bit jumbled up.Hope I will be able to explain. I am extracting an array from database and the result is somewhat like this.
Array
(
[0] => Array
(
[subject_id] => 5
[subject_name] => Pakistan Studies
[class_title] => Commerce B
[class_id] => 1
)
[1] => Array
(
[subject_id] => 12
[subject_name] => Mathematics
[class_title] => Pre-Engineering
[class_id] => 4
)
[2] => Array
(
[subject_id] => 22
[subject_name] => Physics
[class_title] => Pre-Medical A
[class_id] => 6
)
[3] => Array
(
[subject_id] => 16
[subject_name] => Psychology
[class_title] => Humanities
[class_id] => 2
)
[4] => Array
(
[subject_id] => 16
[subject_name] => Psychology
[class_title] => Humanities
[class_id] => 2
)
[5] => Array
(
[subject_id] => 15
[subject_name] => Accounting I
[class_title] => Commerce B
[class_id] => 1
)
[6] => Array
(
[subject_id] => 6
[subject_name] => Computer
[class_title] => Commerce B
[class_id] => 1
)
[7] => Array
(
[subject_id] => 6
[subject_name] => Computer
[class_title] => Pre-Engineering
[class_id] => 4
)
)
I want to get result in this form
Array(['Commerce'=>'Computer','Accounting','Pakistan Studies'],
['Pre-Engineering' =>'Computer','Mathematics'],
['Humanities' => 'Psycholgy'])
Can ANybody please suggest what logics can be applied in PHP. Would be really grateful. Here is the screen shot
RiggsFolly :
This can be achieved with a simple foreach loop creating a new array in the format you want
foreach($array as $in){
$new[$in['class_title']][] = $in['subject_name'];
}
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=376737&siteId=1