开发者

how to get result in single array?

HI,

this is my array coming in a variable

Array
(
    [msg] => Array
        (
            [0] => Array
                (
                    [alertId] => 2416
                    [alerttitle] => Raven Lexy
                    [alertImageUrl] => photos/81951b37ad01c4aa65662956f178214eth.jpeg
                    [alertDescription] => (1) New Message(s)
                    [alertType] => New Message
                    [Date] => 1304679217
                    [count] => 1
                )

        )

    [rehp] => Array
        (
            [0] => Array
                (
                    [alertId] => 48
                    [alerttitle] => Artin
                    [alertImageUrl] => photos/95eaf8416ee68981ab944465bcdd7bffth.jpeg
                    [alertDescription] => Reply F开发者_开发百科rom Artin
                    [alertType] => Reply To Hotpress
                    [count] => 1
                    [id] => 48
                )

            [1] => Array
                (
                    [alertId] => 48
                    [alerttitle] => Artin
                    [alertImageUrl] => photos/95eaf8416ee68981ab944465bcdd7bffth.jpeg
                    [alertDescription] => Reply From Artin
                    [alertType] => Reply To Hotpress
                    [count] => 1
                    [id] => 48
                )

i want to convert into

Array
(

            [0] => Array
                (
                    [alertId] => 2416
                    [alerttitle] => Raven Lexy
                    [alertImageUrl] => photos/81951b37ad01c4aa65662956f178214eth.jpeg
                    [alertDescription] => (1) New Message(s)
                    [alertType] => New Message
                    [Date] => 1304679217
                    [count] => 1
                )

            [1] => Array
                (
                    [alertId] => 48
                    [alerttitle] => Artin
                    [alertImageUrl] => photos/95eaf8416ee68981ab944465bcdd7bffth.jpeg
                    [alertDescription] => Reply From Artin
                    [alertType] => Reply To Hotpress
                    [count] => 1
                    [id] => 48
                )

            [2] => Array
                (
                    [alertId] => 48
                    [alerttitle] => Artin
                    [alertImageUrl] => photos/95eaf8416ee68981ab944465bcdd7bffth.jpeg
                    [alertDescription] => Reply From Artin
                    [alertType] => Reply To Hotpress
                    [count] => 1
                    [id] => 48
                )
)

how can i use foreach loop/for loop to get the the result.

thanks


What about

$new_array = array_merge($orig["msg"],$orig["rehp"])


Simple foreach loop and concatenating the arrays:

$result = array();

foreach($array as $a) {
    $result = array_merge($result, $a);
}


This works and has been tested:

$a = Array(
    "msg" => Array
        (
            0 => Array
                (
                    "alertId" => 2416,
                    "alerttitle" => "Raven Lexy",
                    "alertImageUrl" => "photos/81951b37ad01c4aa65662956f178214eth.jpeg",
                    "alertDescription" => "(1) New Message(s)",
                    "alertType" => "New Message",
                    "Date" => 1304679217,
                    "count" => 1
                )

        ),

    "rehp" => Array
        (
            0 => Array
                (
                    "alertId" => 48,
                    "alerttitle" => "Artin",
                    "alertImageUrl" => "photos/95eaf8416ee68981ab944465bcdd7bffth.jpeg",
                    "alertDescription" => "Reply From Artin",
                    "alertType" => "Reply To Hotpress",
                    "count" => 1,
                    "id" => 48
                ),

            1 => Array
                (
                    "alertId" => 48,
                    "alerttitle" => "Artin",
                    "alertImageUrl" => "photos/95eaf8416ee68981ab944465bcdd7bffth.jpeg",
                    "alertDescription" => "Reply From Artin",
                    "alertType" => "Reply To Hotpress",
                    "count" => 1,
                    "id" => 48,
                )
    )
);

$b = array();
foreach ($a as $v)
{
    foreach ($v as $i)
        $b[] = $i;
}

print_r($b);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜