lethalMango
lethalMango

Reputation: 4491

PHP Change Array Structure / Format

I have an array at present that looks like this:

Array
(
    [0] => Array
        (
            [language] => English
        )

    [1] => Array
        (
            [language] => Arabic
        )

    [2] => Array
        (
            [language] => Bengali
        )
)

What I'd like to do is change it so it looks like this:

Array
(
    [language] => Array
        (
            [0] => English
            [1] => Arabic
            [2] => Bengali
        )
)

I also have an array that looks like this:

Array
(
       [id] => 3
       [name] => lethalMango
       [joined] => 2010-01-01 00:00:00
)

And I'd like to change it to:

Array
(
    [user] => Array
        (
           [id] => 3
           [name] => lethalMango
           [joined] => 2010-01-01 00:00:00
        )
)

I've tried a number of methods without much success but I'm sure there is an more efficient way.

Upvotes: 1

Views: 564

Answers (2)

KingCrunch
KingCrunch

Reputation: 131841

Second

$result = array('user'=>$array);

Upvotes: 1

Gaurav
Gaurav

Reputation: 28755

FIRST : 

$result = array();
foreach($array as $value){
  $result['language'][]= $value['language']
}



SECOND : 

 $result['user'] = $array;

Upvotes: 4

Related Questions