[ create a new paste ] login | about

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

PHP, pasted on May 14:
<?php
$array1 = array
(
    array
        (
                'cid' => 1,
                'value' => 'red'
        )

    ,array
        (
                'cid' => 2,
                'value' => 'green'
        )

    ,array
        (
                cid => 3,
                value => 'pink'
        )

    ,array
        (
                cid => 4,
                value => 'yellow'
        )
);

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

$temp = array();
foreach ($array1 as $val) {
  $temp[$val['cid']] = $val['value'];
}

//Now you have an array:
print_r($temp);

//Then you can easily use that in the second array
$new= array();
foreach ($array2 as $key=>$val) {
  $new[$key] = $temp[$val];
}

print_r($new);
?>


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
Array
(
    [1] => red
    [2] => green
    [3] => pink
    [4] => yellow
)
Array
(
    [0] => green
    [1] => pink
    [2] => red
)


Create a new paste based on this one


Comments: