Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Hello i have array like this

   [0] => Array
            (
                [ExamMonth] => Array
                    (
                        [name] => MAY
                    )

                [ExamType] => Array
                    (
                        [exam_type] => Grades
                    )

                [Month] => Array
                    (
                        [class_subject_id] => 0
                        [marks_obtained] => 0
                        [grade] => 
                    )

                [Subject] => Array
                    (
                        [subject_name] => Punjabi
                    )

            )

        [1] => Array
            (
                [ExamMonth] => Array
                    (
                        [name] => MAY
                    )

                [ExamType] => Array
                    (
                        [exam_type] => Examinations
                    )

                [Month] => Array
                    (
                        [class_subject_id] => 0
                        [marks_obtained] => 124
                        [grade] => a
                    )

                [Subject] => Array
                    (
                        [subject_name] => Mathematics
                    )

            )

        [2] => Array
            (
                [ExamMonth] => Array
                    (
                        [name] => MAY
                    )

                [ExamType] => Array
                    (
                        [exam_type] => Examinations
                    )

                [Month] => Array
                    (
                        [class_subject_id] => 0
                        [marks_obtained] => 124
                        [grade] => 
                    )

                [Subject] => Array
                    (
                        [subject_name] => Physical Edu
                    )

            )

        [3] => Array
            (
                [ExamMonth] => Array
                    (
                        [name] => MAY
                    )

                [ExamType] => Array
                    (
                        [exam_type] => Examinations
                    )

                [Month] => Array
                    (
                        [class_subject_id] => 0
                        [marks_obtained] => 124
                        [grade] => a
                    )

                [Subject] => Array
                    (
                        [subject_name] => Hindi
                    )

            )

        [4] => Array
            (
                [ExamMonth] => Array
                    (
                        [name] => SEPTEMBER
                    )

                [ExamType] => Array
                    (
                        [exam_type] => Examinations
                    )

                [Month] => Array
                    (
                        [class_subject_id] => 0
                        [marks_obtained] => 124
                        [grade] => a
                    )

                [Subject] => Array
                    (
                        [subject_name] => Hindi
                    )

            )

        [5] => Array
            (
                [ExamMonth] => Array
                    (
                        [name] => SEPTEMBER
                    )

                [ExamType] => Array
                    (
                        [exam_type] => Examinations
                    )

                [Month] => Array
                    (
                        [class_subject_id] => 0
                        [marks_obtained] => 124
                        [grade] => a
                    )

                [Subject] => Array
                    (
                        [subject_name] => Hindi
                    )

            )

        [6] => Array
            (
                [ExamMonth] => Array
                    (
                        [name] => SEPTEMBER
                    )

                [ExamType] => Array
                    (
                        [exam_type] => Examinations
                    )

                [Month] => Array
                    (
                        [class_subject_id] => 0
                        [marks_obtained] => 124
                        [grade] => a
                    )

                [Subject] => Array
                    (
                        [subject_name] => Geography
                    )

            )

    )

But i need array like

[May]=>Array {
             [0]=>Array (
 [ExamType] => Array
                    (
                        [exam_type] => Grades
                    )

                [Month] => Array
                    (
                        [class_subject_id] => 0
                        [marks_obtained] => 0
                        [grade] => 
                    )

                [Subject] => Array
                    (
                        [subject_name] => Punjabi
                    )
    )
So on 
[September ]=>Array

}

I have no idea how to do this. Can anybody tell me how to do this ?

Thanks in advance

share|improve this question
add comment

closed as too localized by Brad Larson Feb 1 '13 at 17:24

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

3 Answers

up vote 0 down vote accepted

Something like this can do the trick:

foreach ($yourArray as $exam) {
  $newArray[$exam['ExamMonth']['month']][] = array(
    'ExamType' => $exam['ExamType'],
    // etc.
  );
}
share|improve this answer
add comment

something like this should work:

$newArr = array();
foreach($months as $month) {
  $newArr[$month['ExamMonth']['name']] = $month;
  unset($newArr[$month['ExamMonth']]);
}
share|improve this answer
add comment

The main wrong bit are the brackets. The array is defined within (). Also, I hope it's pseudo-code, as it's not a complete valid statement. This would be a complete instance:

$School = array
    (
    [May]=>Array
         (
         [0]=>Array
             (
             [ExamType] => Array  ( [exam_type] => Grades )
             [Month] => Array (
                              [class_subject_id] => 0
                              [marks_obtained] => 0
                              [grade] => 
                              )
             [Subject] => Array ( [subject_name] => Punjabi )
             )
         [1]=>Array
             (
             [ExamType] => Array  ( [exam_type] => Grades )
             [Month] => Array (
                              [class_subject_id] => 0
                              [marks_obtained] => 0
                              [grade] => 
                              )
             [Subject] => Array ( [subject_name] => Punjabi2 )
             )
         )
    [Juny]=>Array
         (
         [2]=>Array
             (
             [ExamType] => Array  ( [exam_type] => Grades )
             [Month] => Array (
                              [class_subject_id] => 0
                              [marks_obtained] => 0
                              [grade] => 
                              )
             [Subject] => Array ( [subject_name] => Punjabi )
             )
         )
    )
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.