You are here: array sorting « PHP « IT news, forums, messages
array sorting

Posted by Merlin on 03/28/05 08:52

Hi there,

I would like to save some db power by putting values into a file which are often
used. They basicly populate a select field.
So I placed those values into associative arrays:
$code[language] = array("1"=> "php", "2"=> "asp");

Now I would like to sort those for displaying after my preference, not by lets
say alphabet. The easiest thing I could think of, is just to move the entry:
$code[language] = array("2"=> "asp", "1"=> "php");

But this of course does not work. I would like to be able to place values later
on inbetween. So if somebody comes up with a language called ".net" :-) I would
like to place it in the middle, but I cant get it to work like that :-(

To build the select box I use following code:

<select name="education">
<option value ="0" selected>---</option>
';
################################################
# build the select field
for ($i=1; $i <= count($code[education]); $i++){
if ($education)
$isselected = ($i == $education) ? " selected" : ""; // select the active row
else
$isselected = FALSE;
printf ("<option value =\"%s\"%s>%s</option>\n", $i, $isselected,
$code[education][$i]);
};
################################################
echo'
</select>

Has anybody an idea which could help me on that? Thank you for any help.

Merlin

 

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

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