Php 在laravel中合并和合并数组
在合并阵列时,我得到了许多信息。 我在laravl中使用了array\u merge和array\u combine,但没有成功Php 在laravel中合并和合并数组,php,laravel,laravel-5,Php,Laravel,Laravel 5,在合并阵列时,我得到了许多信息。 我在laravl中使用了array\u merge和array\u combine,但没有成功 array:4 [▼ "resident_id" => array:19 [▼ 2 => "2" 1841 => "1841" ] "community_id" => array:19 [▼ 2 => "
array:4 [▼
"resident_id" => array:19 [▼
2 => "2"
1841 => "1841"
]
"community_id" => array:19 [▼
2 => "25"
1841 => "25"
1843 => "25"
]
"out_of_community" => array:5 [▼
2 =>
"2020-09-25"
1841 =>
"2020-09-25"
"
]
i want
resident_id community_id out_of_community
2 25 2020-09-25
1841 25 2020-09-25
请帮我解决它
是的
$arr=$request->all();
$a=阵列合并($arr) 我不确定array\u merge是否是一种方法。看起来您正在尝试将数据转换为由每个子数组中的键/ID标识的表格格式。以下是一种可能适合您的方法:
$keyCodes = array_keys($array['resident_id']); //get the keys to use when constructing the transposed array. $array is your data array
$dataToTabularFormat = [];
collect($keyCodes)->each(function($keyCode) use (&$dataToTabularFormat, $array) {
collect($array)->each(
function($item, $key) use($keyCode, &$dataToTabularFormat ) {
$dataToTabularFormat[$keyCode][$key] = $item[$keyCode] ;
}
);
});
现在,您可以使用$dataToTabularFormat
填充表。在刀片视图中,您可以执行以下操作:
@foreach($dataToTabularFormat as $item)
{{ $item['resident_id' }} {{ $item['community_id' }} {{ $item['out_of_community']}}
@endforeach
我不确定数组合并是否可行。看起来您正在尝试将数据转换为由每个子数组中的键/ID标识的表格格式。以下是一种可能适合您的方法:
$keyCodes = array_keys($array['resident_id']); //get the keys to use when constructing the transposed array. $array is your data array
$dataToTabularFormat = [];
collect($keyCodes)->each(function($keyCode) use (&$dataToTabularFormat, $array) {
collect($array)->each(
function($item, $key) use($keyCode, &$dataToTabularFormat ) {
$dataToTabularFormat[$keyCode][$key] = $item[$keyCode] ;
}
);
});
现在,您可以使用$dataToTabularFormat
填充表。在刀片视图中,您可以执行以下操作:
@foreach($dataToTabularFormat as $item)
{{ $item['resident_id' }} {{ $item['community_id' }} {{ $item['out_of_community']}}
@endforeach