如何获得单个数组的结果?

发布于 2024-11-05 14:55:11 字数 2823 浏览 1 评论 0原文

嗨,

这是我的数组,它是一个变量,

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
                )

我想将其转换为

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
                )
)

如何使用 foreach 循环/for 循环来获取结果。

谢谢

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 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
                )

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

就此别过 2024-11-12 14:55:11

怎么样

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

What about

$new_array = array_merge($orig["msg"],$orig["rehp"])
月亮邮递员 2024-11-12 14:55:11

简单的 foreach 循环并连接数组:

$result = array();

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

Simple foreach loop and concatenating the arrays:

$result = array();

foreach($array as $a) {
    $result = array_merge($result, $a);
}
诺曦 2024-11-12 14:55:11

这有效并且已经过测试:

$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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文