0

I'm using CakePHP 3.6. I have this Array and I want to group this array by season and an episode like this $data["season"]["episode"]; how can I achieve this considering $data has about 1000 index;

i know about Hash::combine() ; but it's just for one level as far as I understand. thanks

 $data =   [
        [
            "episode" => "01" ,
            "season"  => "01" ,
            "name"    => "first" ,
            "...."    => "......." ,
        ] ,
        [
            "episode" => "01" ,
            "season"  => "01" ,
            "name"    => "second" ,
            "...."    => "......." ,
        ] ,
        [
            "episode" => "03" ,
            "season"  => "01" ,
            "name"    => "third" ,
            "...."    => "......." ,
        ] ,
        [
            "episode" => "01" ,
            "season"  => "02" ,
            "name"    => "......." ,
            "...."    => "......." ,
        ] ,
    ];
Hamidreza
  • 694
  • 6
  • 19
  • Simple foreach solution will work fine? – Kuldeep Choudhary Feb 13 '19 at 05:10
  • You have to simply group twice, first by season, then iterate over the groups and group their contents by episode. CakePHP's collection functionality can help you with that. **https://stackoverflow.com/questions/47304495/organize-a-groupby-within-another-groupby-using-collection-in-cakephp**. – ndm Feb 13 '19 at 10:52

0 Answers0