tags:

views:

38

answers:

2

I have the next array

Array ( 
   [0] => Array ( [id] => 22 [title] => RankTitle ) 
   [1] => Array ( [id] => 32 [title] => RankTitle2 ) 
) 

How can I get the next array in php?:

Array ( 
   [22] => RankTitle 
   [32] => RankTitle2 
) 
+4  A: 

You can do this:

$new = array();
foreach ($old as $item) {
    $new[$item['id']] = $item['title'];
}
Gumbo
+1  A: 

Do you mean this?

$array = Array ( 
            [0] => Array ( [id] => 22 [title] => RankTitle ) 
            [1] => Array ( [id] => 32 [title] => RankTitle2 ) 
         ) 

$nextArray = array($array[0]['id'] => $array[0]['title'],
                   $array[1]['id'] => $array[1]['title']);
Axsuul
Ohoho. It is so simple. And so stupid.
Alexander.Plutov
@Alexander.Plutov what is particularly "stupid" about this? This answers your question correctly.
stereofrog
Yes. But if I'll add 100 elements into my first array, this solution grows up in 100 times.
Alexander.Plutov
Yea I was just showing you the concept, it definitely doesn't scale =/
Axsuul