You are here: Re: Sorting an array « All PHP « IT news, forums, messages
Re: Sorting an array

Posted by Paul on 05/26/05 00:27

Kate wrote:
> The number is part of the product code (it is not the product price),
but I
> guess that doesn't change your solution. I was hoping for an "easy"
way to
> sort it without splitting it up into name and value, etc., but maybe
not...
>
>

I don't know exactly how you need it sorted, but here I wrote this
little piece of code which I think will do what you are looking to do....

<?php
$prodArr = array("11USD", "11CAD", "11EUR", "119USD", "201EUR",
"70CAD", "60usd");

$sortOk = usort($prodArr, "customSort");

foreach ($prodArr as $key => $val) {
echo "{$key}: {$val}<br />";
}

function customSort($a, $b) {
$sortKeyA = eregi("[A-Z]{3}", $a, $regsA);
$sortKeyB = eregi("[A-Z]{3}", $b, $regsB);
$sortKeyA = $regsA[0];
$sortKeyB = $regsB[0];
return strcasecmp($sortKeyA, $sortKeyB);
}
?>

Hope this helps,

Take care,

Paul

 

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

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