Remco A
Remco A

Reputation: 147

Merge multiple arrays values into one array value

I have 4 arrays with each 10 elements:

$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

The arrays are all in the same order, so value 1 of $vidtype matches value 1 of $vidcategory,$vidurl and $vidtitle. I am exporting them to an excel file but want to sort $vidtype and $vidtitle in alphabetical order.

If I do that the array values won't match anymore, so my idea was to merge all the values with the same key together and sort $vidtype and $vidtitle in alphabetical order after merging. So the values will still match.

I got stuck on the merge part, I have been searching on stackoverflow for a long time but couldn't find the right answer.

Is my idea clear? Any thoughts?

Upvotes: 1

Views: 96

Answers (1)

Nishit Manjarawala
Nishit Manjarawala

Reputation: 461

this will work

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

Upvotes: 2

Related Questions