Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the array KEY to a value from sub array

This is the set of result from my database

print_r($plan);
Array
(
    [0] => Array
        (
            [id] => 2
            [subscr_unit] => D
            [subscr_period] => 
            [subscr_fee] => 
        )

    [1] => Array
        (
            [id] => 3
            [subscr_unit] => M,Y
            [subscr_period] => 1,1
            [subscr_fee] => 90,1000
        )

    [2] => Array
        (
            [id] => 32
            [subscr_unit] => M,Y
            [subscr_period] => 1,1
            [subscr_fee] => 150,1500
        )

)

How can I change the $plan[0] to $plan[value_of_id]

Thank You.

like image 924
Shishant Avatar asked Mar 06 '10 14:03

Shishant


1 Answers

This won't do it in-place, but:

$new_plan = array();
foreach ($plan as $item)
{
  $new_plan[$item['id']] = $item;
}
like image 171
Tom Avatar answered Sep 20 '22 06:09

Tom