[ create a new paste ] login | about

Link: http://codepad.org/DyudyH1g    [ raw code | output | fork ]

PHP, pasted on Jul 7:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
function some_func($arr, $key) {
    $val = $arr[$key];
    unset($arr[$key]);
    return array_merge(array($key => $val), $arr);
}
$array = array(
    'a' => 'rose',
    'b' => 'tulip',
    'c' => 'dahlia',
    'd' => 'peony',
    'e' => 'magnolia'
);
var_dump(some_func($array, 'c'));


Output:
1
2
3
4
5
6
7
8
9
10
11
12
array(5) {
  ["c"]=>
  string(6) "dahlia"
  ["a"]=>
  string(4) "rose"
  ["b"]=>
  string(5) "tulip"
  ["d"]=>
  string(5) "peony"
  ["e"]=>
  string(8) "magnolia"
}


Create a new paste based on this one


Comments: