【发布时间】:2014-02-08 06:03:16
【问题描述】:
如何在 PHP 中合并 n 个数组。数组的数量由想要提取一些信息的用户数量决定。
我需要做这样的事情
$result = array_merge_recursive ($tweets0, $tweets1, $tweets2, $tweets3, $tweets4, $tweets5, ... n);
我该如何解决?
3 个数组的示例
$tweets0
Array
(
[statuses] => Array
(
)
[search_metadata] => Array
(
[completed_in] => 0.021
[max_id] => 4.2466715126216E+17
[max_id_str] => 424667151262158848
[query] => from%3A%40nopiedra+AND+%23utpl
[refresh_url] => ?since_id=424667151262158848&q=from%3A%40nopiedra%20AND%20%23utpl&result_type=recent
[count] => 50
[since_id] => 0
[since_id_str] => 0
)
)
$tweets1
Array
(
[statuses] => Array
(
[0] => Array
(
[metadata] => Array
(
[result_type] => recent
[iso_language_code] => es
)
[created_at] => Fri Jan 17 18:07:56 +0000 2014
[id] => 4.2424169391194E+17
[id_str] => 424241693911941120
[text] => Alguna alma caritativa de la #utpl podrÃa ayudarme con las pregunta de Expresión oral que bestia ni contabilidad es tan complicada como esta
[source] => Twitter for Android
[truncated] =>
[in_reply_to_status_id] =>
[in_reply_to_status_id_str] =>
[in_reply_to_user_id] =>
[in_reply_to_user_id_str] =>
[in_reply_to_screen_name] =>
[user] => Array
(
[id] => 99147465
[id_str] => 99147465
[name] =>  Steve Cedeño
[screen_name] => stevecede
[location] =>
[description] => Barcelonista ,gusto del rock y en contra del regueton,adicto al Playstation 3... since 1982
[url] => https://t.co/Miwfx1QAu4
)
)
)
[search_metadata] => Array
(
[completed_in] => 0.015
[max_id] => 4.2424169391194E+17
[max_id_str] => 424241693911941120
[query] => from%3A%40stevecede+AND+%23utpl
[refresh_url] => ?since_id=424241693911941120&q=from%3A%40stevecede%20AND%20%23utpl&result_type=recent
[count] => 50
[since_id] => 0
[since_id_str] => 0
)
)
$tweets2
Array
(
[statuses] => Array
(
[0] => Array
(
[metadata] => Array
(
[result_type] => recent
[iso_language_code] => es
)
[created_at] => Sat Jan 18 16:14:56 +0000 2014
[id] => 4.2457564273929E+17
[id_str] => 424575642739290112
[text] => Hall del edificio #UGTI de la #UTPL congestionadÃsimo transite con cuidado... XD
[source] => TweetDeck
[truncated] =>
[in_reply_to_status_id] =>
[in_reply_to_status_id_str] =>
[in_reply_to_user_id] =>
[in_reply_to_user_id_str] =>
[in_reply_to_screen_name] =>
[user] => Array
(
[id] => 14938800
[id_str] => 14938800
[name] => Xavier Jaramillo
[screen_name] => xavito90
[location] => Loja
[description] => Estudiante de IngenierÃa en Sistemas... Del bombillo soy...!!!
[url] => http://t.co/SestnLJ58A
)
)
)
[search_metadata] => Array
(
[completed_in] => 0.017
[max_id] => 4.2457564273929E+17
[max_id_str] => 424575642739290112
[query] => from%3A%40xavito90+AND+%23utpl
[refresh_url] => ?since_id=424575642739290112&q=from%3A%40xavito90%20AND%20%23utpl&result_type=recent
[count] => 50
[since_id] => 0
[since_id_str] => 0
)
)
结果是
Array
(
[statuses] => Array
(
[0] => Array
(
[metadata] => Array
(
[result_type] => recent
[iso_language_code] => es
)
[created_at] => Fri Jan 17 18:07:56 +0000 2014
[id] => 4.2424169391194E+17
[id_str] => 424241693911941120
[text] => Alguna alma caritativa de la #utpl podrÃa ayudarme con las pregunta de Expresión oral que bestia ni contabilidad es tan complicada como esta
[source] => Twitter for Android
[truncated] =>
[in_reply_to_status_id] =>
[in_reply_to_status_id_str] =>
[in_reply_to_user_id] =>
[in_reply_to_user_id_str] =>
[in_reply_to_screen_name] =>
[user] => Array
(
[id] => 99147465
[id_str] => 99147465
[name] =>  Steve Cedeño
[screen_name] => stevecede
[location] =>
[description] => Barcelonista ,gusto del rock y en contra del regueton,adicto al Playstation 3... since 1982
[url] => https://t.co/Miwfx1QAu4
)
)
[1] => Array
(
[metadata] => Array
(
[result_type] => recent
[iso_language_code] => es
)
[created_at] => Sat Jan 18 16:14:56 +0000 2014
[id] => 4.2457564273929E+17
[id_str] => 424575642739290112
[text] => Hall del edificio #UGTI de la #UTPL congestionadÃsimo transite con cuidado... XD
[source] => TweetDeck
[truncated] =>
[in_reply_to_status_id] =>
[in_reply_to_status_id_str] =>
[in_reply_to_user_id] =>
[in_reply_to_user_id_str] =>
[in_reply_to_screen_name] =>
[user] => Array
(
[id] => 14938800
[id_str] => 14938800
[name] => Xavier Jaramillo
[screen_name] => xavito90
[location] => Loja
[description] => Estudiante de IngenierÃa en Sistemas... Del bombillo soy...!!!
[url] => http://t.co/SestnLJ58A
)
)
)
[search_metadata] => Array
(
[completed_in] => Array
(
[0] => 0.021
[1] => 0.015
[2] => 0.017
)
[max_id] => Array
(
[0] => 4.2466715126216E+17
[1] => 4.2424169391194E+17
[2] => 4.2457564273929E+17
)
[max_id_str] => Array
(
[0] => 424667151262158848
[1] => 424241693911941120
[2] => 424575642739290112
)
[query] => Array
(
[0] => from%3A%40nopiedra+AND+%23utpl
[1] => from%3A%40stevecede+AND+%23utpl
[2] => from%3A%40xavito90+AND+%23utpl
)
[refresh_url] => Array
(
[0] => ?since_id=424667151262158848&q=from%3A%40nopiedra%20AND%20%23utpl&result_type=recent
[1] => ?since_id=424241693911941120&q=from%3A%40stevecede%20AND%20%23utpl&result_type=recent
[2] => ?since_id=424575642739290112&q=from%3A%40xavito90%20AND%20%23utpl&result_type=recent
)
[count] => Array
(
[0] => 50
[1] => 50
[2] => 50
)
[since_id] => Array
(
[0] => 0
[1] => 0
[2] => 0
)
[since_id_str] => Array
(
[0] => 0
[1] => 0
[2] => 0
)
)
)
这个结果是用array_merge_recursive($tweets0, $tweets1, $tweets2)实现的,但是当我加入更多的数组时,我该怎么办,不知道是谁的号码
感谢您的帮助
【问题讨论】:
标签: php arrays recursion merge