我在PHP中有这个数组 $ all_designs_from_select_articles 。每个索引都包含对象Design:
array:7 [▼
0 => array:12 [▼
0 => Design {#297 ▶}
1 => Design {#298 ▶}
2 => Design {#299 ▶}
3 => Design {#300 ▶}
4 => Design {#301 ▶}
5 => Design {#302 ▶}
6 => Design {#303 ▶}
7 => Design {#304 ▶}
8 => Design {#305 ▶}
9 => Design {#306 ▶}
10 => Design {#307 ▶}
11 => Design {#308 ▶}
]
1 => array:15 [▼
0 => Design {#309 ▶}
1 => Design {#310 ▶}
2 => Design {#311 ▶}
3 => Design {#312 ▶}
4 => Design {#313 ▶}
5 => Design {#314 ▶}
6 => Design {#315 ▶}
7 => Design {#316 ▶}
8 => Design {#317 ▶}
9 => Design {#318 ▶}
10 => Design {#319 ▶}
11 => Design {#320 ▶}
12 => Design {#321 ▶}
13 => Design {#322 ▶}
14 => Design {#323 ▶}
]
]
但我想要一个包含所有设计键的数组,如下所示:
array:26 [▼
0 => Design {#297 ▶}
1 => Design {#298 ▶}
2 => Design {#299 ▶}
3 => Design {#300 ▶}
4 => Design {#301 ▶}
5 => Design {#302 ▶}
6 => Design {#303 ▶}
7 => Design {#304 ▶}
8 => Design {#305 ▶}
9 => Design {#306 ▶}
10 => Design {#307 ▶}
11 => Design {#308 ▶}
12 => Design {#309 ▶}
13 => Design {#310 ▶}
14 => Design {#311 ▶}
15 => Design {#312 ▶}
16 => Design {#313 ▶}
17 => Design {#314 ▶}
18 => Design {#315 ▶}
19 => Design {#316 ▶}
20 => Design {#317 ▶}
21 => Design {#318 ▶}
22 => Design {#319 ▶}
23 => Design {#320 ▶}
24 => Design {#321 ▶}
25 => Design {#322 ▶}
26 => Design {#323 ▶}
...
etc
]
这是我对API的查询并获取第一个数组值:
foreach ($search_articles as $article) {
$all_designs_from_select_articles[] = ApiDesign::getList([
'article_id' => $article,
'visibility' => 'ALL',
'order' => '-POPULARITY,NAME',
'lang' => 'multi,es',
]);
}
PHP中是否有一个函数可以执行此操作? 我正在使用PHP7和框架laravel 5.2
答案 0 :(得分:1)
您可以使用
将事后的子阵列合并在一起$(function(){
$( "#frmActiontest" ).submit(function( event ) {
var url = $(this).attr('action');
$.ajax({
url: url,
data: $("#frmActiontest").serialize(),
type: $(this).attr('method')
}).done(function(data) {
//window.location.href="http://neuronguru.com/MedAdmin/tests/";
window.location.reload();
/*$('#result').html(data);
$('#frmActiontest')[0].reset();*/
});
event.preventDefault();
});
$( ".test" ).on("click",function(event) {
var url = $(this).data('url');
var actionUrl = $(this).data('actionurl');
console.log(actionUrl);
$("#frmActiontest").attr('action',actionUrl);
$.ajax({
url: url,
type: "GET",
dataType: 'json'
}).done(function(data) {
data=data[0];
$("#myModalTestLabel").html("Update Test");
$("#simulationId").val(data.simulationId);
$("#testTitle").val(data.testTitle);
$("#description").val(data.description);
//$("#contents").val(data.contents);
$("#tid").val(data.id);
$("#testModal").trigger("click");
console.log(data);
});
event.preventDefault();
});
});
this is my ajax function for the above question
或者在创建数组期间:
$all_designs_from_select_articles = array_reduce(
$all_designs_from_select_articles, "array_merge", []);
我认为我更喜欢后一种方法,但这是一种边缘偏好。
答案 1 :(得分:0)
我没有测试过这段代码,但它应该像使用array_merge()一样简单。
$newArray = array_merge($array[0], $array[1]);