Hey everyone, I have a list of results that I am storing in an array after I run the SQL query. There were a lot of duplicates in the array so I used the clean() function to resolve that. That worked just as I wanted, except for one thing: As seen below, the numbers of each item are 0,1, then 13. Is there any way to make this numbered from 0-2? I was thinking implode the array to a string then re-import to a new array to renumber everything but wasn't having luck there. Array ( [0] => Outing: basketball outing [1] => Outing: test outing [13] => Outing: family) Code (markup): Anyone have any ideas?
Assuming the original array is structured as in your initial post (throughout), you can do the following: $formatted_array = array_values($original_array); PHP: Which saves you from looping.
Well that only applies sometimes, when what you want to achieve is very basic, looping wouldn't be an issue. However in the case, if you really want to consider speed, do a benchmark and let me know how that goes - I'd be interested to see which approach is faster.
I'd be interested in knowing too - I've always done it the array_values way. $quantity = count( array_values( $array ) );