473,387 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Sort an array

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

Feb 21 '06 #1
3 1341
iavian wrote:
Hi
How do we sort 3 dimensional array by sorting on 3 , 2 and 1st
dimensions?
Regards
Vijay


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
Feb 21 '06 #2
$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

Feb 21 '06 #3
iavian wrote:
$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


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

Feb 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: lawrence | last post by:
Is there an easy way to sort a 2 dimensional array alphabetically by the second field in each row? Also, when I use sort() on a two dimensional array, it seems to work a lot like...
4
by: its me | last post by:
Let's say I have a class of people... Public Class People Public Sex as String Public Age as int Public Name as string end class And I declare an array of this class...
4
by: Brett | last post by:
I have two arrays and i wish to sort the first one numerically, but after sorting, I would like the second array to be in the same matching order as the first array. ie. @l1={3,1,2};...
40
by: Elijah Bailey | last post by:
I want to sort a set of records using STL's sort() function, but dont see an easy way to do it. I have a char *data; which has size mn bytes where m is size of the record and n is the...
7
by: ritchie | last post by:
Hi all, I am new to this group and I have question that you may be able to help me with. I am trying to learn C but am currently stuck on this. First of all, I have a function for each sort...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
5
by: Jan Smith | last post by:
I've searched the overloads for the Array.Sort method, and I haven't found a clear answer to my question. Maybe it's not in Array.Sort. Here's the question: I initialize an array X with the...
1
by: Marcus Kwok | last post by:
I wrote a little test program to demonstrate what may be a misunderstanding on my part in the behavior of ArrayList::Sort(). I defined a class (Test) that has two data members: a System::String*...
48
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
4
by: Santosh Nayak | last post by:
Hi, Is it possible to sort the array of struct based on the data members. e.g. struct { int a ; float b ; char c ; } TEMP ;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.