1

我有一个数组。我想改变他们的顺序。这是一个我只想使用数组的数组。我只需要使用数组来执行此操作。

    Array
    (
        [Abhijit Singh] => Array
            (
                [Physics] => Array
                    (


                        [Assignment] => Array
                            (
                                [StudentName] => Abhijit Singh
                                [FatherName] => Mr. Pawanjit Singh
                                [housename] => Aitchison
                                [RollNo] => 11556
                                [ExamMonth] => APRIL
                                [SubjectName] => Physics
                                [MarksObtained] => 10
                                [MaxMarks] => 100
                                [ExamType] => Assignment
                                [Grade] => 
                            )

                        [Wednesday Tests] => Array
                            (
                                [StudentName] => Abhijit Singh
                                [FatherName] => Mr. Pawanjit Singh
                                [housename] => Aitchison
                                [RollNo] => 11556
                                [ExamMonth] => APRIL
                                [SubjectName] => Physics
                                [MarksObtained] => 1
                                [MaxMarks] => 100
                                [ExamType] => Wednesday Tests
                                [Grade] => 
                            )

                        [Examinations] => Array
                            (
                                [StudentName] => Abhijit Singh
                                [FatherName] => Mr. Pawanjit Singh
                                [housename] => Aitchison
                                [RollNo] => 11556
                                [ExamMonth] => APRIL
                                [SubjectName] => Physics
                                [MarksObtained] => 100
                                [MaxMarks] => 100
                                [ExamType] => Examinations
                                [Grade] => 
                            )

                        [Projects] => Array
                            (
                                [StudentName] => Abhijit Singh
                                [FatherName] => Mr. Pawanjit Singh
                                [housename] => Aitchison
                                [RollNo] => 11556
                                [ExamMonth] => APRIL
                                [SubjectName] => Physics
                                [MarksObtained] => 10
                                [MaxMarks] => 100
                                [ExamType] => Projects
                                [Grade] => 
                            )

                    )

                [History] => Array
                    (
                        [Examinations] => Array
                            (
                                [StudentName] => Abhijit Singh
                                [FatherName] => Mr. Pawanjit Singh
                                [housename] => Aitchison
                                [RollNo] => 11556
                                [ExamMonth] => APRIL
                                [SubjectName] => History
                                [MarksObtained] => 20
                                [MaxMarks] => 100
                                [ExamType] => Examinations
                                [Grade] => 
                            )

                        [Projects] => Array
                            (
                                [StudentName] => Abhijit Singh
                                [FatherName] => Mr. Pawanjit Singh
                                [housename] => Aitchison
                                [RollNo] => 11556
                                [ExamMonth] => APRIL
                                [SubjectName] => History
                                [MarksObtained] => 20
                                [MaxMarks] => 100
                                [ExamType] => Projects
                                [Grade] => 
                            )

                        [Grades] => Array
                            (
                                [StudentName] => Abhijit Singh
                                [FatherName] => Mr. Pawanjit Singh
                                [housename] => Aitchison
                                [RollNo] => 11556
                                [ExamMonth] => APRIL
                                [SubjectName] => History
                                [MarksObtained] => 0
                                [MaxMarks] => 0
                                [ExamType] => Grades
                                [Grade] => 20
                            )



                    )

                [Hindi] => Array
                    (
                        [Projects] => Array
                            (


                [StudentName] => Abhijit Singh
                            [FatherName] => Mr. Pawanjit Singh
                            [housename] => Aitchison
                            [RollNo] => 11556
                            [ExamMonth] => APRIL
                            [SubjectName] => Hindi
                            [MarksObtained] => 12
                            [MaxMarks] => 100
                            [ExamType] => Projects
                            [Grade] => 
                        )




                    [Examinations] => Array
                        (
                            [StudentName] => Abhijit Singh
                            [FatherName] => Mr. Pawanjit Singh
                            [housename] => Aitchison
                            [RollNo] => 11556
                            [ExamMonth] => APRIL
                            [SubjectName] => Hindi
                            [MarksObtained] => 12
                            [MaxMarks] => 100
                            [ExamType] => Examinations
                            [Grade] => 
                        )

                )

            [Econimics] => Array
                (
                    [Wednesday Tests] => Array
                        (
                            [StudentName] => Abhijit Singh
                            [FatherName] => Mr. Pawanjit Singh
                            [housename] => Aitchison
                            [RollNo] => 11556
                            [ExamMonth] => APRIL
                            [SubjectName] => Econimics
                            [MarksObtained] => 2
                            [MaxMarks] => 100
                            [ExamType] => Wednesday Tests
                            [Grade] => 
                        )

                    [Examinations] => Array
                        (
                            [StudentName] => Abhijit Singh
                            [FatherName] => Mr. Pawanjit Singh
                            [housename] => Aitchison
                            [RollNo] => 11556
                            [ExamMonth] => APRIL
                            [SubjectName] => Econimics
                            [MarksObtained] => 20
                            [MaxMarks] => 100
                            [ExamType] => Examinations
                            [Grade] => 
                        )


                )

            [Chemsitry] => Array
                (
                    [Grades] => Array
                        (
                            [StudentName] => Abhijit Singh
                            [FatherName] => Mr. Pawanjit Singh
                            [housename] => Aitchison
                            [RollNo] => 11556
                            [ExamMonth] => APRIL
                            [SubjectName] => Chemsitry
                            [MarksObtained] => 0
                            [MaxMarks] => 0
                            [ExamType] => Grades
                            [Grade] => 20
                        )

                    [Assignment] => Array
                        (
                            [StudentName] => Abhijit Singh
                            [FatherName] => Mr. Pawanjit Singh
                            [housename] => Aitchison
                            [RollNo] => 11556
                            [ExamMonth] => APRIL
                            [SubjectName] => Chemsitry
                            [MarksObtained] => 20
                            [MaxMarks] => 100
                            [ExamType] => Assignment
                            [Grade] => 
                        )

                    [Wednesday Tests] => Array
                        (
                            [StudentName] => Abhijit Singh
                            [FatherName] => Mr. Pawanjit Singh
                            [housename] => Aitchison
                            [RollNo] => 11556
                            [ExamMonth] => APRIL
                            [SubjectName] => Chemsitry
                            [MarksObtained] => 20
                            [MaxMarks] => 100
                            [ExamType] => Wednesday Tests
                            [Grade] => 
                        )

                    [Examinations] => Array
                        (
                            [StudentName] => Abhijit Singh
                            [FatherName] => Mr. Pawanjit Singh
                            [housename] => Aitchison
                            [RollNo] => 11556
                            [ExamMonth] => APRIL
                            [SubjectName] => Chemsitry
                            [MarksObtained] => 20
                            [MaxMarks] => 100
                            [ExamType] => Examinations
                            [Grade] => 
                        )

                    [Projects] => Array
                        (
                            [StudentName] => Abhijit Singh
                            [FatherName] => Mr. Pawanjit Singh
                            [housename] => Aitchison
                            [RollNo] => 11556
                            [ExamMonth] => APRIL
                            [SubjectName] => Chemsitry
                            [MarksObtained] => 20
                            [MaxMarks] => 100
                            [ExamType] => Projects
                            [Grade] => 
                        )

                )

            [Geo] => Array
                (
                    [Grades] => Array
                        (
                            [Grade] => NULL
                        )

                    [Assignment] => Array
                        (
                            [MarksObtained] => NULL
                        )

                    [Wednesday Tests] => Array
                        (
                            [MarksObtained] => NULL
                        )

                    [Examinations] => Array
                        (
                            [MarksObtained] => NULL
                        )

                    [Projects] => Array
                        (
                            [MarksObtained] => NULL
                        )

                )

        )
 [Vaishali Bhalla] => Array
        (
            [Chemsitry] => Array
                (
                    [Examinations] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => Chemsitry
                            [MarksObtained] => 
                            [MaxMarks] => 100
                            [ExamType] => Examinations
                            [Grade] => 
                        )

                    [Projects] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => Chemsitry
                            [MarksObtained] => 
                            [MaxMarks] => 100
                            [ExamType] => Projects
                            [Grade] => 
                        )

                    [Grades] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => Chemsitry
                            [MarksObtained] => 0
                            [MaxMarks] => 0
                            [ExamType] => Grades
                            [Grade] => 
                        )

                    [Assignment] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => Chemsitry
                            [MarksObtained] => 
                            [MaxMarks] => 100
                            [ExamType] => Assignment
                            [Grade] => 
                        )

                    [Wednesday Tests] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => Chemsitry
                            [MarksObtained] => 
                            [MaxMarks] => 100
                            [ExamType] => Wednesday Tests
                            [Grade] => 
                        )

                )

            [History] => Array
                (
                    [Assignment] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => History
                            [MarksObtained] => 
                            [MaxMarks] => 100
                            [ExamType] => Assignment
                            [Grade] => 
                        )

                    [Wednesday Tests] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => History
                            [MarksObtained] => 
                            [MaxMarks] => 100
                            [ExamType] => Wednesday Tests
                            [Grade] => 
                        )

                    [Examinations] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => History
                            [MarksObtained] => 
                            [MaxMarks] => 100
                            [ExamType] => Examinations
                            [Grade] => 
                        )

                    [Projects] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => History
                            [MarksObtained] => 
                            [MaxMarks] => 100
                            [ExamType] => Projects
                            [Grade] => 
                        )

                    [Grades] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => History
                            [MarksObtained] => 0
                            [MaxMarks] => 0
                            [ExamType] => Grades
                            [Grade] => 
                        )

                )

            [Physics] => Array
                (
                    [Projects] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => Physics
                            [MarksObtained] => 
                            [MaxMarks] => 100
                            [ExamType] => Projects
                            [Grade] => 
                        )

                    [Grades] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => Physics
                            [MarksObtained] => 0
                            [MaxMarks] => 0
                            [ExamType] => Grades
                            [Grade] => 
                        )

                    [Assignment] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => Physics
                            [MarksObtained] => 
                            [MaxMarks] => 100
                            [ExamType] => Assignment
                            [Grade] => 
                        )

                    [Wednesday Tests] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => Physics
                            [MarksObtained] => 
                            [MaxMarks] => 100
                            [ExamType] => Wednesday Tests
                            [Grade] => 
                        )

                    [Examinations] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => Physics
                            [MarksObtained] => 
                            [MaxMarks] => 100
                            [ExamType] => Examinations
                            [Grade] => 
                        )

                )

            [Econimics] => Array
                (
                    [Grades] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => Econimics
                            [MarksObtained] => 0
                            [MaxMarks] => 0
                            [ExamType] => Grades
                            [Grade] => 
                        )

                    [Assignment] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => Econimics
                            [MarksObtained] => 
                            [MaxMarks] => 100
                            [ExamType] => Assignment
                            [Grade] => 
                        )

                    [Wednesday Tests] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => Econimics
                            [MarksObtained] => 
                            [MaxMarks] => 100
                            [ExamType] => Wednesday Tests
                            [Grade] => 
                        )

                    [Examinations] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => Econimics
                            [MarksObtained] => 
                            [MaxMarks] => 100
                            [ExamType] => Examinations
                            [Grade] => 
                        )

                    [Projects] => Array
                        (
                            [StudentName] => Vaishali Bhalla
                            [FatherName] => Mr. Atul Bhalla
                            [housename] => 
                            [RollNo] => 10794
                            [ExamMonth] => APRIL
                            [SubjectName] => Econimics
                            [MarksObtained] => 
                            [MaxMarks] => 100
                            [ExamType] => Projects
                            [Grade] => 
                        )

                )

            [Hindi] => Array
                (
                    [Grades] => Array
                        (
                            [Grade] => NULL
                        )

                    [Assignment] => Array
                        (
                            [MarksObtained] => NULL
                        )

                    [Wednesday Tests] => Array
                        (
                            [MarksObtained] => NULL
                        )

                    [Examinations] => Array
                        (
                            [MarksObtained] => NULL
                        )

                    [Projects] => Array
                        (
                            [MarksObtained] => NULL
                        )

                )

            [Geo] => Array
                (
                    [Grades] => Array
                        (
                            [Grade] => NULL
                        )

                    [Assignment] => Array
                        (
                            [MarksObtained] => NULL
                        )

                    [Wednesday Tests] => Array
                        (
                            [MarksObtained] => NULL
                        )

                    [Examinations] => Array
                        (
                            [MarksObtained] => NULL
                        )

                    [Projects] => Array
                        (
                            [MarksObtained] => NULL
                        )

                )

        )

)

该数组的长度可能会有所不同。现在,我想按字母顺序重新排列主题名称的顺序。

有人知道如何做到这一点吗?

谢谢

4

2 回答 2

1

您应该真正研究对象,您在数组中保存了复杂的数据结构,这提供了难以维护且不直观的代码。

这是一个关于php中对象的教程

http://php.net/manual/en/language.oop5.php

如果您坚持使用数组(并且没有充分的理由这样做),您可以使用 php 的内置排序功能

http://php.net/manual/en/function.sort.php

或者

http://www.php.net/manual/en/function.natsort.php

取决于你到底要完成什么。

这两个页面都提供了使用示例。

于 2012-04-24T11:12:51.713 回答
0

试试这个:

foreach ($arr as $key => $val) {
    ksort($val);
    $temp[$key] = $val;
}
于 2012-04-24T11:53:29.760 回答