Jump to content

Sorting multidimensional array


Nico7430

Recommended Posts

I want to create an array based on data in a multidimensional array. Take, for example:

 

$table[1] = array('husband' => array ('firstname'=> 'Albert',

                                                          'lastname' => 'Einstein',

                                                          'age'      => 129),

                          'wife'        => array ('firstname' => 'Mileva',

                                                          'lastname'  => 'Einstein',

                                                          'age'      => 128));

 

What would be the best approach, when you want to

create an array with only the last names or the ages? Are there some

things like wildcards in the PHP array universe to skip the first array level?

 

Any suggestion is very appreciated. I tried several strategies, but ended up creating the same mulitdimensional array as above.

Link to comment
https://forums.phpfreaks.com/topic/229911-sorting-multidimensional-array/
Share on other sites

@ Jasonrichardsmith: I have to admit that what I am searching for, is a bit more complicated than my first post in this thread. I work a lot with xml and try to understand how php works with xml. Every time I import attributes and want to do something with them (sort them, select them, etcetera), I get those multidimensional arrays which I don't know how to use...

 

The problem looked very much like the example I gave in my first post here. Indeed, I took that example from the Wrox introduction on php, but I have to say... the first time I saw that example, I wondered already what somebody needed to do when he/she would like to use this array in a way it was not designed for...

 

I can put my whole project here, but... I rather like to put it simple and then try it further on my own.

 

Silkfire: thanks a lot! It works. That was the code I was looking for.  :shy:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.