Jump to content

Ordering results via. price (advanced)


Anidazen

Recommended Posts

Hello.

I really hope somebody can help me. I've got a complicated results ordering question.

Basically, I've got some prices in an array called $pricearray, and it looks something like this.

$pricearray[$i] = array("site logo", "site name", "site url", "site url 2", $sub-price-array);


So it's some information about the seller, and $pricearray[4] contains an array of prices for different objects.

Now [b]before[/b] the fourth field was turned into an array, I was able to re-order $pricearray via the price contained in value 4 of the array. Someone on this forum was kind enough to supply me with the following code for doing this, months ago.

[code]$tmp = array();
foreach($pricearray as $k => $v) {
$tmp[$k] = $v[8];
}
asort($tmp);
$new = array();
foreach($tmp as $k => $v) {
$new[] = $pricearray[$k];
}[/code]


$new would basically be $pricearray but re-ordered based on the value of field number 4 in the array.

The problem is I've never understood what's going on in this code, so I'm helpless to adapt it! I need it sorted by the value in $pricearray[4][$i] basically, where $i is the object number.


I hope this makes sense.


Edit: I believe the 8 in the quoted code should be a 4. This is because $pricearray now has fewer values than when I copied/pasted that bit of code. However, I've tried changing the "$tmp[$k] = $v[8];" into "$tmp[$k] = $v[8][$i];" and it doesn't achieve the desired result.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.