1

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?

4
  • Possible duplicate of Combine two arrays Commented Mar 9, 2017 at 10:06
  • You can create one array and merge it into one. then sort data by any field. Commented Mar 9, 2017 at 10:09
  • Try array_push to merge all arrays Commented Mar 9, 2017 at 10:10
  • Do you maybe have an example? I don't really get what you mean @Evgeniy Commented Mar 9, 2017 at 10:26

1 Answer 1

2

this will work

$abc=array();
for($i=0;$i<10;$i++){
$abc[$i]=array($vidtype[$i],$vidcategory[$i],$vidurl[$i],$vidtitle[$i]);
}
Sign up to request clarification or add additional context in comments.

2 Comments

I get this notice:Undefined offset: 1. Seems like the structure is good since I get this returned: [1] => Array ( [0] => [1] => [2] => [3] => )
can u send screen shoot?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.