FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » uasort strange problem
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
uasort strange problem [message #173429] Tue, 12 April 2011 22:38 Go to next message
Peter is currently offline  Peter
Messages: 15
Registered: March 2003
Karma: 0
Junior Member
Hi all,

I currently have a list of products stored in a multi-dimensional array
which contains, amongst other fields, the product's name, heading
'name', and the product's price, heading 'price' and I want to be able
to sort the array by name ascending/descending and price
ascending/descending.

The array is originally created from a mysql database using various
tables and so I have not been able to create a simple, mysql query that
allows me to return the data already sorted. There are various reasons
for this which I don't wish to go into here, being a php forum.

So I found out about the uasort function, plus a small routine that
seemed to be just what I was looking for to allow me to sort on either
'name' or 'price' ascending. I then discovered the array_reverse
function which I thought would allow me to reverse the array to allow me
to have 'name' or 'price' descending options.

At least that's what I thought, but I'm new to both functions and so I
might be missing something obvious and so hope that someone here can
point out my mistakes.

Here's the problem. If I just compare on either 'name' or 'price'
ascending the array remains unsorted. If I compare on either 'name' or
'price' ascending and then use the array_reverse function it works like
a charm and the array is perfectly sorted in descending order. So what
I'm not getting is this, how can an array that remains unsorted when
using either of my compare functions, suddenly become sorted when
reversed?

Hope someone here can explain.

Here is the php that I am using to sort the array:

switch($searchtype){
case '1':
uasort($array, 'compare_nameAsc'); // sort on name ascending
break;

case '2':
uasort($array, 'compare_nameAsc'); // sort on name ascending
$array = array_reverse($array); // reverse the sort order
break;

case '3':
uasort($array, 'compare_priceAsc'); // sort on price ascending
break;

case '4':
uasort($array3, 'compare_priceAsc'); // sort on price ascending
$array = array_reverse($array); // reverse the sort order
break;
}

And here are the 2 functions:

function compare_nameAsc($a, $b)
{
return strnatcmp($a['name'], $b['name']);
}
function compare_priceAsc($a, $b)
{
return strnatcmp($a['price'], $b['price']);
}
--
Pete Ives
Remove All_stRESS before sending me an email
Re: uasort strange problem [message #173430 is a reply to message #173429] Wed, 13 April 2011 01:29 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/12/2011 6:38 PM, Peter wrote:
> Hi all,
>
> I currently have a list of products stored in a multi-dimensional array
> which contains, amongst other fields, the product's name, heading
> 'name', and the product's price, heading 'price' and I want to be able
> to sort the array by name ascending/descending and price
> ascending/descending.
>
> The array is originally created from a mysql database using various
> tables and so I have not been able to create a simple, mysql query that
> allows me to return the data already sorted. There are various reasons
> for this which I don't wish to go into here, being a php forum.
>
> So I found out about the uasort function, plus a small routine that
> seemed to be just what I was looking for to allow me to sort on either
> 'name' or 'price' ascending. I then discovered the array_reverse
> function which I thought would allow me to reverse the array to allow me
> to have 'name' or 'price' descending options.
>
> At least that's what I thought, but I'm new to both functions and so I
> might be missing something obvious and so hope that someone here can
> point out my mistakes.
>
> Here's the problem. If I just compare on either 'name' or 'price'
> ascending the array remains unsorted. If I compare on either 'name' or
> 'price' ascending and then use the array_reverse function it works like
> a charm and the array is perfectly sorted in descending order. So what
> I'm not getting is this, how can an array that remains unsorted when
> using either of my compare functions, suddenly become sorted when
> reversed?
>
> Hope someone here can explain.
>
> Here is the php that I am using to sort the array:
>
> switch($searchtype){
> case '1':
> uasort($array, 'compare_nameAsc'); // sort on name ascending
> break;
>
> case '2':
> uasort($array, 'compare_nameAsc'); // sort on name ascending
> $array = array_reverse($array); // reverse the sort order
> break;
>
> case '3':
> uasort($array, 'compare_priceAsc'); // sort on price ascending
> break;
>
> case '4':
> uasort($array3, 'compare_priceAsc'); // sort on price ascending
> $array = array_reverse($array); // reverse the sort order
> break;
> }
>
> And here are the 2 functions:
>
> function compare_nameAsc($a, $b)
> {
> return strnatcmp($a['name'], $b['name']);
> }
> function compare_priceAsc($a, $b)
> {
> return strnatcmp($a['price'], $b['price']);
> }

How are you displaying the items? uasort() maintains the key/value
association, but array_reverse() does not by default.

P.S. In general, it's better to let the database do the sorting. Maybe
you would like to follow up on that end in comp.databases.mysql.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: uasort strange problem [message #173447 is a reply to message #173429] Wed, 13 April 2011 11:18 Go to previous messageGo to next message
crankypuss is currently offline  crankypuss
Messages: 147
Registered: March 2011
Karma: 0
Senior Member
Peter <pete(dot)ivesAll_stRESS(at)blueyonder(dot)co(dot)uk> wrote:

> Hi all,
>
> I currently have a list of products stored in a multi-dimensional array
> which contains, amongst other fields, the product's name, heading
> 'name', and the product's price, heading 'price' and I want to be able
> to sort the array by name ascending/descending and price
> ascending/descending.
>
> The array is originally created from a mysql database using various
> tables and so I have not been able to create a simple, mysql query that
> allows me to return the data already sorted. There are various reasons
> for this which I don't wish to go into here, being a php forum.

With most relational databases (I don't use mySQL) you can set up
separate views that contain only a subset of the data and have it kept
sorted. Generally a view doesn't cost much at all in terms of
performance.

--
no aluminum siding offers today
Re: uasort strange problem [message #173458 is a reply to message #173430] Wed, 13 April 2011 18:32 Go to previous messageGo to next message
Peter is currently offline  Peter
Messages: 15
Registered: March 2003
Karma: 0
Junior Member
In article <io2u9e$mi3$1(at)dont-email(dot)me>, jstucklex(at)attglobal(dot)net says...
> On 4/12/2011 6:38 PM, Peter wrote:
>> Hi all,
>>
>> I currently have a list of products stored in a multi-dimensional array
>> which contains, amongst other fields, the product's name, heading
>> 'name', and the product's price, heading 'price' and I want to be able
>> to sort the array by name ascending/descending and price
>> ascending/descending.
>>
>> The array is originally created from a mysql database using various
>> tables and so I have not been able to create a simple, mysql query that
>> allows me to return the data already sorted. There are various reasons
>> for this which I don't wish to go into here, being a php forum.
>>
>> So I found out about the uasort function, plus a small routine that
>> seemed to be just what I was looking for to allow me to sort on either
>> 'name' or 'price' ascending. I then discovered the array_reverse
>> function which I thought would allow me to reverse the array to allow me
>> to have 'name' or 'price' descending options.
>>
>> At least that's what I thought, but I'm new to both functions and so I
>> might be missing something obvious and so hope that someone here can
>> point out my mistakes.
>>
>> Here's the problem. If I just compare on either 'name' or 'price'
>> ascending the array remains unsorted. If I compare on either 'name' or
>> 'price' ascending and then use the array_reverse function it works like
>> a charm and the array is perfectly sorted in descending order. So what
>> I'm not getting is this, how can an array that remains unsorted when
>> using either of my compare functions, suddenly become sorted when
>> reversed?
>>
>> Hope someone here can explain.
>>
>> Here is the php that I am using to sort the array:
>>
>> switch($searchtype){
>> case '1':
>> uasort($array, 'compare_nameAsc'); // sort on name ascending
>> break;
>>
>> case '2':
>> uasort($array, 'compare_nameAsc'); // sort on name ascending
>> $array = array_reverse($array); // reverse the sort order
>> break;
>>
>> case '3':
>> uasort($array, 'compare_priceAsc'); // sort on price ascending
>> break;
>>
>> case '4':
>> uasort($array3, 'compare_priceAsc'); // sort on price ascending
>> $array = array_reverse($array); // reverse the sort order
>> break;
>> }
>>
>> And here are the 2 functions:
>>
>> function compare_nameAsc($a, $b)
>> {
>> return strnatcmp($a['name'], $b['name']);
>> }
>> function compare_priceAsc($a, $b)
>> {
>> return strnatcmp($a['price'], $b['price']);
>> }
>
> How are you displaying the items? uasort() maintains the key/value
> association, but array_reverse() does not by default.
>

The items are products that are returned when the user searches the
database using whichever keywords they enter.

> P.S. In general, it's better to let the database do the sorting. Maybe
> you would like to follow up on that end in comp.databases.mysql.
>
>
Like I said, it's not really an option. The results are originally
ordered by relevancy based upon looking in the product name and...

Any records that have the complete matching string in them, then
Any records where the string contains all words but not in any order,
then
Any record that contains any of the words used in the search string

After that I then have to search on more detailed product information
using the same criteria

I have steered well clear of even attempting any SQL query to allow me
to perform such a search that would allow me to return the records in
the correct order, so I have to copy all queries to any array and then
remove any duplicates.

If you believe this may be possible then I'll certainly ask this in
comp.databases.mysql.

--
Pete Ives
Remove All_stRESS before sending me an email
Re: uasort strange problem [message #173461 is a reply to message #173458] Wed, 13 April 2011 18:47 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Peter)

> In article <io2u9e$mi3$1(at)dont-email(dot)me>, jstucklex(at)attglobal(dot)net says...
>
>> P.S. In general, it's better to let the database do the sorting. Maybe
>> you would like to follow up on that end in comp.databases.mysql.
>>
> Like I said, it's not really an option. The results are originally
> ordered by relevancy based upon looking in the product name and...
>
> Any records that have the complete matching string in them, then
> Any records where the string contains all words but not in any order,
> then
> Any record that contains any of the words used in the search string
>
> After that I then have to search on more detailed product information
> using the same criteria
>
> I have steered well clear of even attempting any SQL query to allow me
> to perform such a search that would allow me to return the records in
> the correct order, so I have to copy all queries to any array and then
> remove any duplicates.
>
> If you believe this may be possible then I'll certainly ask this in
> comp.databases.mysql.

It should definitely be possible. You can sort by many different
criteria. You can create values for sorting "at runtime" (e.g. a "1" for
a complete match and a "2" for a partly match, then take these numbers
into account for sorting). And if nothing else helps you can use sub
queries, combine their results and then sort that final result set.

Micha
Re: uasort strange problem [message #173465 is a reply to message #173458] Wed, 13 April 2011 20:53 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Wed, 13 Apr 2011 19:32:15 +0100, Peter wrote:

> In article <io2u9e$mi3$1(at)dont-email(dot)me>, jstucklex(at)attglobal(dot)net says...
>> On 4/12/2011 6:38 PM, Peter wrote:
>>> Hi all,
>>>
>>> I currently have a list of products stored in a multi-dimensional
>>> array which contains, amongst other fields, the product's name,
>>> heading 'name', and the product's price, heading 'price' and I want
>>> to be able to sort the array by name ascending/descending and price
>>> ascending/descending.
>>>
>>> The array is originally created from a mysql database using various
>>> tables and so I have not been able to create a simple, mysql query
>>> that allows me to return the data already sorted. There are various
>>> reasons for this which I don't wish to go into here, being a php
>>> forum.
>>>
>>> So I found out about the uasort function, plus a small routine that
>>> seemed to be just what I was looking for to allow me to sort on
>>> either 'name' or 'price' ascending. I then discovered the
>>> array_reverse function which I thought would allow me to reverse the
>>> array to allow me to have 'name' or 'price' descending options.
>>>
>>> At least that's what I thought, but I'm new to both functions and so
>>> I might be missing something obvious and so hope that someone here
>>> can point out my mistakes.
>>>
>>> Here's the problem. If I just compare on either 'name' or 'price'
>>> ascending the array remains unsorted. If I compare on either 'name'
>>> or 'price' ascending and then use the array_reverse function it works
>>> like a charm and the array is perfectly sorted in descending order.
>>> So what I'm not getting is this, how can an array that remains
>>> unsorted when using either of my compare functions, suddenly become
>>> sorted when reversed?
>>>
>>> Hope someone here can explain.
>>>
>>> Here is the php that I am using to sort the array:
>>>
>>> switch($searchtype){
>>> case '1':
>>> uasort($array, 'compare_nameAsc'); // sort on name ascending
break;
>>>
>>> case '2':
>>> uasort($array, 'compare_nameAsc'); // sort on name ascending
$array
>>> = array_reverse($array); // reverse the sort order break;
>>>
>>> case '3':
>>> uasort($array, 'compare_priceAsc'); // sort on price ascending
>>> break;
>>>
>>> case '4':
>>> uasort($array3, 'compare_priceAsc'); // sort on price ascending
>>> $array = array_reverse($array); // reverse the sort order break;
>>> }
>>>
>>> And here are the 2 functions:
>>>
>>> function compare_nameAsc($a, $b)
>>> {
>>> return strnatcmp($a['name'], $b['name']);
>>> }
>>> function compare_priceAsc($a, $b)
>>> {
>>> return strnatcmp($a['price'], $b['price']);
>>> }
>>
>> How are you displaying the items? uasort() maintains the key/value
>> association, but array_reverse() does not by default.

> The items are products that are returned when the user searches the
> database using whichever keywords they enter.

You didn't answer what Jerry asked.

For example, are you using:

foreach ($array as $value) {
do_something_with ($value);
}

or:

for ($index = 0; $index < length($array); $index = $index + 1) {
do_something_with ($array['$index']);
}

or some other method of looping through and showing the array contents
when you determine whether the "sort" has worked or not?

I think that the former will show the sorted result, but the latter will
show the array according to the original key values.

Rgds

Denis McMahon
Re: uasort strange problem [message #173467 is a reply to message #173465] Wed, 13 April 2011 22:34 Go to previous messageGo to next message
Peter is currently offline  Peter
Messages: 15
Registered: March 2003
Karma: 0
Junior Member
In article <4da60d5c$0$12063$bed64819(at)gradwell(dot)net>,
denis(dot)m(dot)f(dot)mcmahon(at)gmail(dot)com says...
> On Wed, 13 Apr 2011 19:32:15 +0100, Peter wrote:
>
>> In article <io2u9e$mi3$1(at)dont-email(dot)me>, jstucklex(at)attglobal(dot)net says...
>>> On 4/12/2011 6:38 PM, Peter wrote:
>>>> Hi all,
>>>>
>>>> I currently have a list of products stored in a multi-dimensional
>>>> array which contains, amongst other fields, the product's name,
>>>> heading 'name', and the product's price, heading 'price' and I want
>>>> to be able to sort the array by name ascending/descending and price
>>>> ascending/descending.
>>>>
>>>> The array is originally created from a mysql database using various
>>>> tables and so I have not been able to create a simple, mysql query
>>>> that allows me to return the data already sorted. There are various
>>>> reasons for this which I don't wish to go into here, being a php
>>>> forum.
>>>>
>>>> So I found out about the uasort function, plus a small routine that
>>>> seemed to be just what I was looking for to allow me to sort on
>>>> either 'name' or 'price' ascending. I then discovered the
>>>> array_reverse function which I thought would allow me to reverse the
>>>> array to allow me to have 'name' or 'price' descending options.
>>>>
>>>> At least that's what I thought, but I'm new to both functions and so
>>>> I might be missing something obvious and so hope that someone here
>>>> can point out my mistakes.
>>>>
>>>> Here's the problem. If I just compare on either 'name' or 'price'
>>>> ascending the array remains unsorted. If I compare on either 'name'
>>>> or 'price' ascending and then use the array_reverse function it works
>>>> like a charm and the array is perfectly sorted in descending order.
>>>> So what I'm not getting is this, how can an array that remains
>>>> unsorted when using either of my compare functions, suddenly become
>>>> sorted when reversed?
>>>>
>>>> Hope someone here can explain.
>>>>
>>>> Here is the php that I am using to sort the array:
>>>>
>>>> switch($searchtype){
>>>> case '1':
>>>> uasort($array, 'compare_nameAsc'); // sort on name ascending
> break;
>>>>
>>>> case '2':
>>>> uasort($array, 'compare_nameAsc'); // sort on name ascending
> $array
>>>> = array_reverse($array); // reverse the sort order break;
>>>>
>>>> case '3':
>>>> uasort($array, 'compare_priceAsc'); // sort on price ascending
>>>> break;
>>>>
>>>> case '4':
>>>> uasort($array3, 'compare_priceAsc'); // sort on price ascending
>>>> $array = array_reverse($array); // reverse the sort order break;
>>>> }
>>>>
>>>> And here are the 2 functions:
>>>>
>>>> function compare_nameAsc($a, $b)
>>>> {
>>>> return strnatcmp($a['name'], $b['name']);
>>>> }
>>>> function compare_priceAsc($a, $b)
>>>> {
>>>> return strnatcmp($a['price'], $b['price']);
>>>> }
>>>
>>> How are you displaying the items? uasort() maintains the key/value
>>> association, but array_reverse() does not by default.
>
>> The items are products that are returned when the user searches the
>> database using whichever keywords they enter.
>
> You didn't answer what Jerry asked.
>
> For example, are you using:
>
> foreach ($array as $value) {
> do_something_with ($value);
> }
>
> or:
>
> for ($index = 0; $index < length($array); $index = $index + 1) {
> do_something_with ($array['$index']);
> }
>
> or some other method of looping through and showing the array contents
> when you determine whether the "sort" has worked or not?
>
> I think that the former will show the sorted result, but the latter will
> show the array according to the original key values.
>

Well I was using print_r($array) to view the array as text as well as
using a while loop to iterate through the array from $array[0] to $array
[N] where N is the total unduplicated matches found.

Anyway, thanks to Jerry for pointing me in the right direction as far as
uasort. It does maintain the key value associations, which I hadn't
noticed. Oops!! So $array[0] was moved sorted along with the rest of the
record data, which was not what I wanted. I needed $array[0] to hold the
freshly sorted lowest record, be that either first in a-z or lowest
price, etc.

So I tried usort() instead and now everything works just great.

--
Pete Ives
Remove All_stRESS before sending me an email
Re: uasort strange problem [message #173469 is a reply to message #173467] Thu, 14 April 2011 03:06 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/13/2011 6:34 PM, Peter wrote:
> In article<4da60d5c$0$12063$bed64819(at)gradwell(dot)net>,
> denis(dot)m(dot)f(dot)mcmahon(at)gmail(dot)com says...
>> On Wed, 13 Apr 2011 19:32:15 +0100, Peter wrote:
>>
>>> In article<io2u9e$mi3$1(at)dont-email(dot)me>, jstucklex(at)attglobal(dot)net says...
>>>> On 4/12/2011 6:38 PM, Peter wrote:
>>>> > Hi all,
>>>> >
>>>> > I currently have a list of products stored in a multi-dimensional
>>>> > array which contains, amongst other fields, the product's name,
>>>> > heading 'name', and the product's price, heading 'price' and I want
>>>> > to be able to sort the array by name ascending/descending and price
>>>> > ascending/descending.
>>>> >
>>>> > The array is originally created from a mysql database using various
>>>> > tables and so I have not been able to create a simple, mysql query
>>>> > that allows me to return the data already sorted. There are various
>>>> > reasons for this which I don't wish to go into here, being a php
>>>> > forum.
>>>> >
>>>> > So I found out about the uasort function, plus a small routine that
>>>> > seemed to be just what I was looking for to allow me to sort on
>>>> > either 'name' or 'price' ascending. I then discovered the
>>>> > array_reverse function which I thought would allow me to reverse the
>>>> > array to allow me to have 'name' or 'price' descending options.
>>>> >
>>>> > At least that's what I thought, but I'm new to both functions and so
>>>> > I might be missing something obvious and so hope that someone here
>>>> > can point out my mistakes.
>>>> >
>>>> > Here's the problem. If I just compare on either 'name' or 'price'
>>>> > ascending the array remains unsorted. If I compare on either 'name'
>>>> > or 'price' ascending and then use the array_reverse function it works
>>>> > like a charm and the array is perfectly sorted in descending order.
>>>> > So what I'm not getting is this, how can an array that remains
>>>> > unsorted when using either of my compare functions, suddenly become
>>>> > sorted when reversed?
>>>> >
>>>> > Hope someone here can explain.
>>>> >
>>>> > Here is the php that I am using to sort the array:
>>>> >
>>>> > switch($searchtype){
>>>> > case '1':
>>>> > uasort($array, 'compare_nameAsc'); // sort on name ascending
>> break;
>>>> >
>>>> > case '2':
>>>> > uasort($array, 'compare_nameAsc'); // sort on name ascending
>> $array
>>>> > = array_reverse($array); // reverse the sort order break;
>>>> >
>>>> > case '3':
>>>> > uasort($array, 'compare_priceAsc'); // sort on price ascending
>>>> > break;
>>>> >
>>>> > case '4':
>>>> > uasort($array3, 'compare_priceAsc'); // sort on price ascending
>>>> > $array = array_reverse($array); // reverse the sort order break;
>>>> > }
>>>> >
>>>> > And here are the 2 functions:
>>>> >
>>>> > function compare_nameAsc($a, $b)
>>>> > {
>>>> > return strnatcmp($a['name'], $b['name']);
>>>> > }
>>>> > function compare_priceAsc($a, $b)
>>>> > {
>>>> > return strnatcmp($a['price'], $b['price']);
>>>> > }
>>>>
>>>> How are you displaying the items? uasort() maintains the key/value
>>>> association, but array_reverse() does not by default.
>>
>>> The items are products that are returned when the user searches the
>>> database using whichever keywords they enter.
>>
>> You didn't answer what Jerry asked.
>>
>> For example, are you using:
>>
>> foreach ($array as $value) {
>> do_something_with ($value);
>> }
>>
>> or:
>>
>> for ($index = 0; $index< length($array); $index = $index + 1) {
>> do_something_with ($array['$index']);
>> }
>>
>> or some other method of looping through and showing the array contents
>> when you determine whether the "sort" has worked or not?
>>
>> I think that the former will show the sorted result, but the latter will
>> show the array according to the original key values.
>>
>
> Well I was using print_r($array) to view the array as text as well as
> using a while loop to iterate through the array from $array[0] to $array
> [N] where N is the total unduplicated matches found.
>
> Anyway, thanks to Jerry for pointing me in the right direction as far as
> uasort. It does maintain the key value associations, which I hadn't
> noticed. Oops!! So $array[0] was moved sorted along with the rest of the
> record data, which was not what I wanted. I needed $array[0] to hold the
> freshly sorted lowest record, be that either first in a-z or lowest
> price, etc.
>
> So I tried usort() instead and now everything works just great.
>

No, you don't. Just use foreach instead of a for loop. It will display
the array in the sorted order.

Remember - in PHP, ALL indeicies are associative - there is not an
integer key. So item[3] could easily precede item[0], item[1] and item[2].

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: uasort strange problem [message #173489 is a reply to message #173469] Fri, 15 April 2011 19:39 Go to previous message
Peter is currently offline  Peter
Messages: 15
Registered: March 2003
Karma: 0
Junior Member
In article <io5oas$v9n$1(at)dont-email(dot)me>, jstucklex(at)attglobal(dot)net says...
> On 4/13/2011 6:34 PM, Peter wrote:
>> In article<4da60d5c$0$12063$bed64819(at)gradwell(dot)net>,
>> denis(dot)m(dot)f(dot)mcmahon(at)gmail(dot)com says...
>>> On Wed, 13 Apr 2011 19:32:15 +0100, Peter wrote:
>>>
>>>> In article<io2u9e$mi3$1(at)dont-email(dot)me>, jstucklex(at)attglobal(dot)net says...
>>>> > On 4/12/2011 6:38 PM, Peter wrote:
>>>> >> Hi all,
>>>> >>
>>>> >
>>>
>>
>> Well I was using print_r($array) to view the array as text as well as
>> using a while loop to iterate through the array from $array[0] to $array
>> [N] where N is the total unduplicated matches found.
>>
>> Anyway, thanks to Jerry for pointing me in the right direction as far as
>> uasort. It does maintain the key value associations, which I hadn't
>> noticed. Oops!! So $array[0] was moved sorted along with the rest of the
>> record data, which was not what I wanted. I needed $array[0] to hold the
>> freshly sorted lowest record, be that either first in a-z or lowest
>> price, etc.
>>
>> So I tried usort() instead and now everything works just great.
>>
>
> No, you don't. Just use foreach instead of a for loop. It will display
> the array in the sorted order.
>
> Remember - in PHP, ALL indeicies are associative - there is not an
> integer key. So item[3] could easily precede item[0], item[1] and item[2].
>
>

Ok Jerry, will give it a try.

--
Pete Ives
Remove All_stRESS before sending me an email
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Joomla, Wordpress, Expression Web
Next Topic: How can I serialize zend_http_request object?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 10 14:10:56 GMT 2024

Total time taken to generate the page: 0.02017 seconds