You are here: Re: help sorting a 2 dimentional array « PHP Language « IT news, forums, messages
Re: help sorting a 2 dimentional array

Posted by Me, Myself, and I on 12/16/05 02:53

Hello all,

For anyone who is interested here's the answer.

$keylist = array_keys($this->TableArrayRes[0]);
foreach ($this->TableArrayRes as $key => $row) {
foreach($keylist as $arraykey){
eval("\$$arraykey" . '[$key]=$row[\''. $arraykey .'\'];');
}
}
eval('array_multisort(' . $this->TableArraySort . '$this->TableArrayRes);');

James



"Me, Myself, and I" <you@[127.0.0.1]> wrote in message
news:Brmof.21705$Iq3.82510@wagner.videotron.net...
| Hello all,
|
| can someone give me an idea on how to sort a 2 dimentional array (table).
|
| $array = array('Fruit' => 'Apple', 'Price' => 1);
| $array = array('Fruit' => 'orange', 'Price' => 2);
|
| Now this is relatively simple to do when you know the structure of the
| array. However, I am trying to write a function that will sort a two
| dimentional array whose structure I do not know beforehand.
|
|
| based on the example below for array_multisort() on php's documentation
|
| <?php
| // Obtain a list of columns
| foreach ($data as $key => $row) {
| $volume[$key] = $row['volume'];
| $edition[$key] = $row['edition'];
| }
|
| // Sort the data with volume descending, edition ascending
| // Add $data as the last parameter, to sort by the common key
| array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data);
| ?>
|
| I was looking a something along these lines:
|
| ex.
|
| function arraysort ($array,$param){
| $keylist = array_keys($array[0]);
|
| foreach ($array as $key => $row) {
| foreach($keylist as $arraykey){
|
| $$arraykey[$key] = $row[$arraykey];
| }
| }
| array_multisort("$param", $array);
| }
|
| arraysort($somearray,"$firstcol, SORT_DESC, $secondcol, SORT_ASC");
|
|
| my first problem lies with $$arraykey[$key] and what I need is a hint on
how
| to create a dynamically named array.
|
| any suggestions?
|
| thanks,
|
| James
|
|

 

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

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