Reply to help sorting a 2 dimentional array

Your name:

Reply:


Posted by Me, Myself, and I on 12/16/05 00:51

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

[Back to original 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

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