<?php

/**
* Using array_merge() to reorder variables keys.
*/

// items in the wrong order.
$variables = array(
'item 3' => 'value 3',
'item 2' => 'value 2',
'item 1' => 'value 1',
);

// Set keys in the correct order. Item values will be overwritten as long as
// all the keys from $variables have a match.
$reorder = array(
'item 1' => NULL,
'item 2' => NULL,
'item 3' => NULL,
);

// The order in $variables will be set according to how $reorder set them.
$variables = array_merge($reorder, $variables);

print var_dump($variables);
// result:
// array(3) {
// ["item 1"]=>
// string(7) "value 1"
// ["item 2"]=>
// string(7) "value 2"
// ["item 3"]=>
// string(7) "value 3"
// }