HI,
这是我的数组进入变量
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循环来获得结果。
感谢
答案 0 :(得分:3)
怎么样?
$new_array = array_merge($orig["msg"],$orig["rehp"])
答案 1 :(得分:1)
简单foreach
循环并连接数组:
$result = array();
foreach($array as $a) {
$result = array_merge($result, $a);
}
答案 2 :(得分:0)
这可行并且已经过测试:
$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);