2017-06-12 36 views
0

TMDB APIから多次元配列があり、ムービーのリストを取っているときは、「release_date」の降順で並べ替える必要があります。それを行う方法を管理していませんでした。手伝ってくれませんか?マルチディメンションTMDB API配列のソート

これは例である:

Array 
(
    [cast] => Array 
     (
      [0] => Array 
       (
        [adult] => 
        [character] => Disappointed Man 
        [credit_id] => 52fe4235c3a36847f800c2f7 
        [id] => 306 
        [original_title] => Beverly Hills Cop III 
        [poster_path] => /tw9gAhqQcBFX0X0XfVbWqUsmzoU.jpg 
        [release_date] => 1994-05-24 
        [title] => Beverly Hills Cop III 
       ) 

      [1] => Array 
       (
        [adult] => 
        [character] => Himself 
        [credit_id] => 52fe43cac3a36847f806fc33 
        [id] => 4539 
        [original_title] => Hearts of Darkness: A Filmmaker's Apocalypse 
        [poster_path] => /iQLXcATpUxrRdEzxoDqzCgYllnT.jpg 
        [release_date] => 1991-09-06 
        [title] => Hearts of Darkness: A Filmmaker's Apocalypse 
       ) 

      [2] => Array 
       (
        [adult] => 
        [character] => Himself 
        [credit_id] => 52fe45809251416c75058c67 
        [id] => 13611 
        [original_title] => Heckler 
        [poster_path] => /n3uZEZVlPmgJz3Pnijz94sw69Ao.jpg 
        [release_date] => 2007-01-01 
        [title] => Heckler 
       ) 

      [3] => Array 
       (
        [adult] => 
        [character] => Himself 
        [credit_id] => 52fe45b59251416c9103bb99 
        [id] => 35795 
        [original_title] => From 'Star Wars' to 'Jedi': The Making of a Saga 
        [poster_path] => /umP3Q7dRTi22MCbGHBmw1Aeo5IZ.jpg 
        [release_date] => 1983-12-03 
        [title] => From 'Star Wars' to 'Jedi': The Making of a Saga 
       ) 

      [4] => Array 
       (
        [adult] => 
        [character] => Himself (voice) 
        [credit_id] => 52fe4624c3a36847f80ef089 
        [id] => 42979 
        [original_title] => Robot Chicken: Star Wars 
        [poster_path] => /kWKspQ7YiQ82xXM1jVbIbqh5OyV.jpg 
        [release_date] => 2007-07-17 
        [title] => Robot Chicken: Star Wars 
       ) 

      [5] => Array 
       (
        [adult] => 
        [character] => Himself 
        [credit_id] => 52fe4684c3a36847f810367f 
        [id] => 44345 
        [original_title] => The Cutting Edge: The Magic of Movie Editing 
        [poster_path] => /oUepcj7iBKirdscldMvYre2pCtX.jpg 
        [release_date] => 2004-01-01 
        [title] => The Cutting Edge: The Magic of Movie Editing 
       ) 
) 

答えて

1
$data = [ 
    'cast' => [ 
     [ 
      'id' => 1, 
      'release_date' => '1994-05-24' 
     ], 
     [ 
      'id' => 2, 
      'release_date' => '1991-09-06' 
     ], 
     [ 
      'id' => 3, 
      'release_date' => '2007-01-01' 
     ], 
     [ 
      'id' => 4, 
      'release_date' => '1983-12-03' 
     ], 
    ] 
]; 

$rows = $data['cast']; 
$releaseDates = array_map('strtotime', array_column($rows, 'release_date')); 
array_multisort($releaseDates, SORT_DESC, $rows); 
$data['cast'] = $rows; 
var_dump($data);