Find order of data inside an array

Posted by user271619 on Stack Overflow See other posts from Stack Overflow or by user271619
Published on 2010-03-30T03:15:51Z Indexed on 2010/03/30 3:23 UTC
Read the original article Hit count: 283

Filed under:
|

I have a simple array of stuff:

$array = array("apples","oranges","strawberries");

I am trying to find the order of the stuff inside the array. (sometimes the order changes, and so do the items)

I'm expecting to get something like this:

"apples" => 0, "oranges => 1, "strawberries => 2

The end result has something to do with database sorting.

Something like this, inside a foreach loop:

UPDATE tbl SET sortorder = $neworder WHERE fruit = '$fruitname'

The $neworder variable would be populated with the new order, inside the array. While the $fruit variable comes from the item inside the array.

© Stack Overflow or respective owner

Related posts about arraylist

Related posts about php