[ create a new paste ] login | about

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

PHP, pasted on Oct 18:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php

$order = array(2,3,1);

$data = array(
    array('id' => 1, 'title' => 'whatever'),
    array('id' => 2, 'title' => 'whatever'),
    array('id' => 3, 'title' => 'whatever')
);

$result = array();
$index = 0;
foreach ($order as $position) {
    $result[$index] = $data[$position - 1];
    $index++;
}

var_dump($result);


Output:
array(3) {
  [0]=>
  array(2) {
    ["id"]=>
    int(2)
    ["title"]=>
    string(8) "whatever"
  }
  [1]=>
  array(2) {
    ["id"]=>
    int(3)
    ["title"]=>
    string(8) "whatever"
  }
  [2]=>
  array(2) {
    ["id"]=>
    int(1)
    ["title"]=>
    string(8) "whatever"
  }
}


Create a new paste based on this one


Comments: