# Sort an array

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
Hi

How do we start 3 dimensional array by sorting on 3 , 2 and 1st
dimensions?

Regards
Vijay

## Re: Sort an array

Hi

How do we sort 3 dimensional array by sorting on 3 , 2 and 1st
dimensions?

Regards
Vijay

## Re: Sort an array

iavian wrote:

Hi,

PHP doesn't really have multidimensional arrays.
What PHP does have is tough to explain, but it is easiest to think of arrays
that have arrays as elements.
that elements can be arrays again.
This can be repeated many times.

So eg: a 5x5x5 array:

// not needed, but makes things easier to read.
\$ar = array();

// fill it
\$ar[0][0] = array(1,2,3,'bla',3.14);
\$ar[0][1] = array(2,3,44,'testing',99);

etc.

untill

\$ar[4][4] = array(44,-34,4,'last',9);

So HOW do you want it sorted now?

Have a look at functions like: uksort at www.php.net
They allow you to write your own compare-function which PHP will use to
sort.

Regards,
Erwin Moller

## Re: Sort an array

\$a[0][0][0] = "A";
\$a[0][0][1] = "B";
\$a[0][0][2] = "C";
\$a[0][1][0] = "D";
\$a[0][1][1] = "E";
\$a[0][1][2] = "F";
\$a[1][0][0] = "A";
\$a[1][0][1] = "B";
\$a[1][0][2] = "C";

it grows like .. i want to sort it

## Re: Sort an array

iavian wrote:

And what do you excatly mean by sorting?
I am not teasing, but WHAT do you expect to roll out after the sorting?

Another array?
How is that structured?

Look, if I go straight ahead with your above example I get:

\$a[0][0][0] = "A";
\$a[1][0][0] = "A";

as first too elements, but both originate from a different array.
What is it you expect/want as output?

So try to formulate what it is you want exectly as output.
While formulating that, the problem might just dissolve. :-)

Regards,
Erwin Moller