I have an associative array of the form:
$input = array("one" => <class object1>,
"two" => <class object2,
... //and so on);
The keys of $input are guaranteed to be unique. I also have a method called moveToHead($key)
which moves the $input[$key]
element to the 0th location of this associative array. I have few questions:
- Is it possible to determine the index of an associative array?
- How to move the array entry for corresponding
$key => $value
pair to the index 0 and retaining the$key
as is? - What could be the best possible way to achieve both of the above points?
I was thinking to do array_flip for 2nd point (a sub solution), but later found out that array_flip
can only be done when array elements are int and string only. Any pointers?