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