将多个数组值合并为一个数组值

时间:2017-03-09 10:04:48

标签: php arrays sorting

我有4个阵列,每个10个元素:

$vidtype = Array ( [0] => Array ( [0] => Sales [1] => Sales [2] => Sales [3] => Sales [4] => Sales [5] => Sales [6] => Sales [7] => Sales [8] => Sales [9] => Sales

$vidcategory = Array ( [0] => Array ( [0] => comfortsystemen [1] => multimediasystemen [2] => assistentiesystemen [3] => multimediasystemen [4] => productfilms [5] => assistentiesystemen [6] => multimediasystemen [7] => productfilms [8] => productfilms [9] => productfilms

$vidurl = Array ( [0] => Array ( [0] => www.youtube.com/video/bOejnFiC88E [1] => www.youtube.com/video/FsVAxrvi6iE [2] => www.youtube.com/video/3lGfTZdVK1s [3] => www.youtube.com/video/hcw8dl73-W4 [4] => www.youtube.com/video/NlHJ5njWVFE [5] => www.youtube.com/video/II68oVm4zro [6] => www.youtube.com/video/tpg9IaOfno4 [7] => www.youtube.com/video/mzbG0JAICu8 [8] => www.youtube.com/video/OgPodRbJ3So [9] => www.youtube.com/video/YfPLB30MSCU

$vidtitle =  Array ( [0] => Array ( [0] => Gesture Control [1] => Volkswagen – Parkmobile [2] => Multi Collision braking system [3] => Mobiele telefoon interface Premium [4] => Maps & More Dock in de up! [5] => Lane Assist [6] => Car-Net Connect [7] => Volkswagen Allesdrager [8] => Volkswagen Bagagebox [9] => Volkswagen fietsendrager

数组的顺序相同,因此$ vidtype的值1与$ vidcategory,$ vidurl和$ vidtitle的值1匹配。我将它们导出到excel文件但是要按字母顺序排序$ vidtype和$ vidtitle。

如果我这样做,数组值将不再匹配,所以我的想法是将所有值与相同的键合并在一起,并在合并后按字母顺序对$ vidtype和$ vidtitle进行排序。所以这些值仍然匹配。

我被困在合并部分,我一直在stackoverflow上搜索很长一段时间,但找不到正确的答案。

我的想法清楚了吗?有什么想法吗?

1 个答案:

答案 0 :(得分:2)

这将起作用

$abc=array();
for($i=0;$i<10;$i++){
$abc[$i]=array($vidtype[$i],$vidcategory[$i],$vidurl[$i],$vidtitle[$i]);
}