I'm looking for a php function that would find array class object value 'FIND_ME' and swap it as first array key if it exists.
Here is my current Array output :
Array (
[0] => stdClass Object ([id] => 1 [uid] => 52 [type] => A_TEST [title] => TITLE [value] => 1 )
[1] => stdClass Object ([id] => 2 [uid] => 52 [type] => TEST [title] => TITLE [value] => 1 )
[2] => stdClass Object ([id] => 3 [uid] => 52 [type] => FIND_ME [title] => TITLE [value] => 1 )
)
And here is the result I need :
Array (
[0] => stdClass Object ([id] => 3 [uid] => 52 [type] => FIND_ME [title] => TITLE [value] => 1 )
[1] => stdClass Object ([id] => 2 [uid] => 52 [type] => TEST [title] => TITLE [value] => 1 )
[2] => stdClass Object ([id] => 1 [uid] => 52 [type] => A_TEST [title] => TITLE [value] => 1 )
)
Result : Array[2] changed and became Array[0] because type => FIND_ME
was found in the array.
Note: I don't care about the order of others keys.
Any idea?
EDIT: Okay I managed to find the key number of type => FIND_ME
using foreach() :
foreach($array as $key => $value) {
if ($value->type == 'FIND_ME') {
$found = $key;
break;
}
}
But how to swap it as first key of the array?