开发者

PHP Change Array Structure / Format

开发者 https://www.devze.com 2023-03-04 21:09 出处:网络
I have an array at present that looks like this: Array ( [0] => Array ( [language] => English ) [1] => Array

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] => le开发者_运维百科thalMango
           [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.


FIRST : 

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



SECOND : 

 $result['user'] = $array;


Second

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

精彩评论

暂无评论...
验证码 换一张
取 消