You are here: AW: [PHP] How to sort a Multidimensional array? « PHP « IT news, forums, messages
AW: [PHP] How to sort a Multidimensional array?

Posted by Mirco Blitz on 03/03/05 01:23

Hi,
Thank you, for the Hint.
I just have looked in German Doc and that is incomplete.
Here is my solution.

If someone has the same problem.

foreach($arr as $key=>$values){
foreach($values as $valkey=>$value){
$$valkey[$key]=$value;
}
}
array_multisort($$_POST["sortby"], $_POST["asc_desc"], $arr);

Greetings
Mirco Blitz

-----Ursprüngliche Nachricht-----
Von: Frank Arensmeier [mailto:frank.arensmeier@nikehydraulics.se]
Gesendet: Mittwoch, 2. März 2005 23:59
An: Mirco Blitz
Cc: php general list
Betreff: Re: [PHP] How to sort a Multidimensional array?

Hello!

This must be one of the most frequently asked questions ever. Anyway, take a
look at the PHP manual. Look for a function called 'foreach'. To put it
simple, with 'foreach' you are able to go through the array step-by-step,
value by value.

For example:

<?php

$arr = array('value1', 'value2', 'value3); foreach ($arr as $key => $value)
{
    echo "Key: $key; Value: $value<br />\n"; // in stead of just echoing the
values and keys, you can e.g. assign the values to another array and sort
them when done } ?>

regards,

frank

2005-03-02 kl. 23.27 skrev Mirco Blitz:

> Hi,
>
> i have a multidimensional array that look like this:
> $arr=array($key=>array('item0key'=>'item0', 'item1key'=>'item1',
> 'item2key'=>'item2', 'item3key'=>'item3', 'item4key'=>'item4'));
>
> Lineview:
> 0 item0key = item0
> item1key = item1
> item2key = item2
> item3key = item3
> item4key = item4
>
> 1 item0key = item0
> item1key = item1
> item2key = item2
> item3key = item3
> item4key = item4
>
> 2 item0key = item0
> item1key = item1
> item2key = item2
> item3key = item3
> item4key = item4
>
> 4 item0key = item0
> item1key = item1
> item2key = item2
> item3key = item3
> item4key = item4
>
> How can I sort such an array, depending on the Userentry by the Item
> values?
>
> Thank you very much
> Mirco Blitz
>

--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация