codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
<?php //this is the input $array = array( 'random' => 1, 'pewpew' => 2, 'temp' => 5, 'xoxo' => 3, 'qweqweqe' => 4, ); //these are the fields that we need $fields = array('random', 'xoxo', 'temp'); //create an array that has the fields as keys (and anything as values) $tmp = array_combine($fields, range(1, count($fields))); //merge the two arrays $result = array_merge($tmp, $array); //now we will have an array that has the keys from $fields in that order and the values from $array; //the only problem is that the extra items form $array are added at the end, so we need to remove them $result = array_splice($result, 0, count($fields));//the final array needs to have the same number of elements as the $fields array //output print_r($result);
Private
[
?
]
Run code
Submit