Q:

Array value as index

I have an array
$term = array(
  0 => array(
    'id'=>'0902001',
    'name'=>'bob',
    'cgpa'=>'3.81',
  ),
  1 => array(
    'id'=>'0902002',
    'name'=>'jhon',
    'cgpa'=>'3.52',
  ),
);

I want to make a new array that the id will be the index for cgpa of new array.
$new_arr = array(
    '0902001' => '3.81',
    '0902002' => '3.52',
);

Thanks!

A:

This should work for you
for ($i=0, $c = count($term); $i<$c; ++$i) {
   $new_arr[$term[$i]['id']] = $term[$i]['cgpa'];
}

