Jump to content

Re-Ordering Elements Of Arrays


Johnny2

Recommended Posts

I have this multidimensional array that I'll call "$Items_Array":

 

array (size=3)
 0 => 
   array (size=3)
     'id' => string '1' (length=1)
     'quantity' => int 1
     'name' => string 'Book' (length=1)
 1 => 
   array (size=3)
     'id' => string '2' (length=1)
     'quantity' => int 5
     'name' => string 'Shirt' (length=29)
 2 => 
   array (size=3)
     'id' => string '3' (length=1)
     'quantity' => int 2
     'name' => string 'Ice-cream' (length=22)

 

I want to re-arrange the order of elements, according to "quantity", so that the one with the largest quantity comes first. The desired result would look like this:

 

array (size=3)
 0 => 
   array (size=3)
     'id' => string '2' (length=1)
     'quantity' => int 5
     'name' => string 'Shirt' (length=29)
 1 => 
   array (size=3)
     'id' => string '3' (length=1)
     'quantity' => int 2
     'name' => string 'Ice-cream' (length=22)
 2 => 
   array (size=3)
     'id' => string '1' (length=1)
     'quantity' => int 1
     'name' => string 'Book' (length=1)

 

Can someone show me how to do this? Is it just an easy PHP command?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...