Say you used to have a nice little array which you’ve since gone and hacked to pieces through various merges, and cuttings, etc., resulting is a rather non-uniform, keyed array mess.
Now in order to return to some sort of sanity it might be a good idea to take that input array of yours and retrieve from it a new array containing all the values (currently finding themselves inhabiting the original mess) but with a bright and shiny new, numerically ordered index.
Easy.
Simply make use of the handy PHP array_values function which basically takes an input array, retrieves all values from it and then creates a new array with all those values tucked behind a nice sequential numeric index.
So for example, an array looking like this {a->tomato,b->apple} would now become {0->tomato,1->apple}.
It really is that simple.
Related Link: http://www.php.net/manual/en/function.array-values.php
You might also enjoy:
-
While you will quickly learn that adding something to an array in PHP is ridiculously easy, finding a way to remove something turns out not to be quite so e ...
-
PHP comes bundled with a range of nifty array sorting functions the simplest of which will simply take your array and sort it either alphabetically or numer ...
-
It's sometimes pretty valuable to reuse array structures if you're kind of doing a task over and over again, and don't necessarily want to recreate the arra ...
-
Sometimes you wish to apply a certain function, be it a built in PHP function or one of your own creations, to each and every value within a particular arra ...
-
A PHP quick tip on something I keep on forgetting. Now while the foreach functionality is great in iterating through an array and returning the array's valu ...