0

I fetched an array from a table

 arr1 = Array
(
    [0] => Array
        (
            [option_value_id] => 30
            [duration_id] => 1
            [price_value] => 13
        )

    [1] => Array
        (
            [option_value_id] => 30
            [duration_id] => 2

            [price_value] => 14
        )

    [2] => Array
        (
            [option_value_id] => 30
            [duration_id] =>3
           [price_value] =>15
 )
[4] => Array
        (


            [option_value_id] => 31
            [duration_id] => 1
            [price_value] => 16

        )

    [5] => Array
        (


            [option_value_id] => 31
            [duration_id] => 2
            [price_value] => 17
        )

    [6] => Array
        (

            [option_value_id] => 31
            [duration_id] =>3
            [price_value] => 18
 )

I need the duration_id as key and option_value_id as key in the duration_id array my resultant array should look like this

Array
    (
        [1] => Array
            (
                [30] => 13
                [31] => 16
            )

        [2] => Array
            (
                [30] => 14
                [31] => 17
            )

        [3] => Array
            (
                [30] => 15
                [31] => 18
            )
)

?>

1 Answer 1

7

This should do the trick:

$result = array();
foreach($arr1 as $val){
    $result[$val['duration_id']][$val['option_value_id']] = $val['price_value'];
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.