2017-04-05 109 views
0

假設我有一個數組,下面我想返回除[年]鍵之外的所有內容。我怎樣才能做到這一點在PHP?對不起,如果這是一個新手問題。返回除數組中的特定鍵以外的所有內容php

Array 
     (
      [0] => Array 
       (
        [filmId] => 61359 
        [url] => http://www.moviemeter.nl/film/61359 
        [title] => Unstoppable 
        [alternative_title] => 
        [year] => 2011 
        [thumbnail] => http://www.moviemeter.nl/images/covers/thumbs/61000/61359.jpg 
        [average] => 0 
        [votes_count] => 0 
        [similarity] => 100.00 
        [directors_text] => geregisseerd door Richard Harrison 
        [actors_text] => met Chen Shilony, Ruben Crow en David Powell 
        [genres_text] => Drama/Komedie 
        [duration] => 90 
       ) 
      [1] => Array 
       (
        [filmId] => 87923 
        [url] => http://www.moviemeter.nl/film/87923 
        [title] => Unstoppable 
        [alternative_title] => 
        [year] => 2011 
        [thumbnail] => http://www.moviemeter.nl/images/covers/thumbs/87000/87923.jpg 
        [average] => 0 
        [votes_count] => 0 
        [similarity] => 100.00 
        [directors_text] => geregisseerd door Example Director 
        [actors_text] => met Actor 1, Actor 2 en Actor 3 
        [genres_text] => Drama/Komedie 
        [duration] => 90 
       ) 
      [2] => Array 
       (
        [filmId] => 68593 
        [url] => http://www.moviemeter.nl/film/68593 
        [title] => Unstoppable 
        [alternative_title] => 
        [year] => 2010 
        [thumbnail] => http://www.moviemeter.nl/images/covers/thumbs/68000/68593.jpg 
        [average] => 3.3 
        [votes_count] => 191 
        [similarity] => 100.00 
        [directors_text] => geregisseerd door Tony Scott 
        [actors_text] => met Denzel Washington, Chris Pine en Rosario Dawson 
        [genres_text] => Actie/Thriller 
        [duration] => 98 
       ) 
      [3] => Array 
       (
        [filmId] => 17931 
        [url] => http://www.moviemeter.nl/film/17931 
        [title] => Unstoppable 
        [alternative_title] => Nine Lives 
        [year] => 2004 
        [thumbnail] => http://www.moviemeter.nl/images/covers/thumbs/17000/17931.jpg 
        [average] => 2.64 
        [votes_count] => 237 
        [similarity] => 100.00 
        [directors_text] => geregisseerd door David Carson 
        [actors_text] => met Wesley Snipes, Jacqueline Obradors en Mark Sheppard 
        [genres_text] => Actie/Thriller 
        [duration] => 96 
       ) 
     ) 

對不起,如果這是一個新手問題。請幫助我,因爲我不知道這是否可能。謝謝。

回答

3
function remove_year_key(&$films) { 
    foreach ($films as &$film) { 
     unset($film["year"]) 
    } 
} 
+1

是的。完善。謝謝。 :) – CloudSeph

+0

絕對,你打賭。 –

+0

我沒有測試它,但它不應該工作。需要在'foreach'中通過引用傳遞'$ film'變量。 –

相關問題