0

サーバーからjson応答(以下に投稿)を受け取りました。ビデオの長さを特定の時間値と比較するために、現在、すべてobject->durationresults配列を foreach ループで分析しています。2 つの質問があります。

  1. たとえば、( foreach メソッドではなく) 期間が 3600 を超えるオブジェクトをすばやくカウントする方法はありますか?

  2. 現在、次のif(foreach ループ内で) を使用して、項目を 1 つの配列にマージしています。

            if ($duration >= $minDuration) {
                $result [] = $tempResult;
    

    where ( $tempResult;isresultsの現在のオブジェクト) 配列から適切な期間を持つすべてのアイテムを選択してマージする高速な方法はあり$result []ますか?

事前にThx

JSONは次のとおりです。

object(stdClass)[2]
  public 'has_next' => boolean true
  public 'next' => string 'http://rutube.ru/api/search/video/?order_by=rank&format=json&no_adult=checked&duration=long&query=%D0%B0%D0%B2%D0%B0%D1%82%D0%B0%D1%80&page=2' (length=141)
  public 'previous' => null
  public 'page' => int 1
  public 'per_page' => int 10
  public 'results' => 
    array (size=10)
      0 => 
        object(stdClass)[3]
          public 'id' => string '31518e25cde4d110f53d5e9ecde62395' (length=32)
          public 'views' => int 1781
          public 'all_tags' => 
            array (size=0)
              ...
          public 'author' => 
            object(stdClass)[4]
              ...
          public 'has_high_quality' => boolean false
          public 'duration' => int 1477
          public 'is_adult' => int 0
          public 'thumbnail_url' => string 'http://pic.rutube.ru/video/e1/69/e169d576721998efe85e5a013091792b.jpg' (length=69)
          public 'avatar' => string '' (length=0)
          public 'html' => string '' (length=0)
          public 'title' => string 'АВАТАР' (length=12)
          public 'description' => string 'АВАТАР' (length=12)
          public 'created_ts' => string '2010-08-08T14:50:32' (length=19)
          public 'author_id' => int 0
          public 'track_id' => int 3476481
          public 'aname' => string '' (length=0)
          public 'is_vip' => int 0
          public 'tv_id' => int 0
          public 'tv_title' => string '' (length=0)
          public 'season' => int 0
          public 'episode' => int 0
          public 'category_id' => int 7
          public 'is_licensed' => int 0
          public 'duration_group' => int 5
      1 => 
        object(stdClass)[5]
          public 'id' => string 'e5b41d2d7080d5f30fe0e7fca41d5abc' (length=32)
          public 'views' => int 2354
          public 'all_tags' => 
            array (size=0)
              ...
          public 'author' => 
            object(stdClass)[6]
              ...
          public 'has_high_quality' => boolean false
          public 'duration' => int 1442
          public 'is_adult' => int 0
          public 'thumbnail_url' => string 'http://pic.rutube.ru/video/ac/44/ac44fc73ab015c12fed5f419357c8216.jpg' (length=69)
          public 'avatar' => string 'user/2b/11/2b1160ed4c17b20ab3e9534bb776e212.jpg' (length=47)
          public 'html' => string '' (length=0)
          public 'title' => string 'Аватар' (length=12)
          public 'description' => string 'Аватар' (length=12)
          public 'created_ts' => string '2011-01-15T00:07:50' (length=19)
          public 'author_id' => int 17352
          public 'track_id' => int 3984946
          public 'aname' => string 'Uchiha_Itach1' (length=13)
          public 'is_vip' => int 0
          public 'tv_id' => int 0
          public 'tv_title' => string '' (length=0)
          public 'season' => int 0
          public 'episode' => int 0
          public 'category_id' => int 7
          public 'is_licensed' => int 0
          public 'duration_group' => int 5
      2 => 
        object(stdClass)[7]
          public 'id' => string 'f1c72b0afb5e5e9ca867a42af7889b26' (length=32)
          public 'views' => int 336
          public 'all_tags' => 
            array (size=0)
              ...
          public 'author' => 
            object(stdClass)[8]
              ...
          public 'has_high_quality' => boolean false
          public 'duration' => int 1442
          public 'is_adult' => int 0
          public 'thumbnail_url' => string 'http://pic.rutube.ru/video/0e/6e/0e6ec1dbf789bf296cd4ed24b528545a.jpg' (length=69)
          public 'avatar' => string 'user/2b/11/2b1160ed4c17b20ab3e9534bb776e212.jpg' (length=47)
          public 'html' => string '' (length=0)
          public 'title' => string 'Аватар' (length=12)
          public 'description' => string 'Аватар' (length=12)
          public 'created_ts' => string '2011-01-15T13:01:42' (length=19)
          public 'author_id' => int 17352
          public 'track_id' => int 3986119
          public 'aname' => string 'Uchiha_Itach1' (length=13)
          public 'is_vip' => int 0
          public 'tv_id' => int 0
          public 'tv_title' => string '' (length=0)
          public 'season' => int 0
          public 'episode' => int 0
          public 'category_id' => int 7
          public 'is_licensed' => int 0
          public 'duration_group' => int 5
      3 => 
        object(stdClass)[9]
          public 'id' => string '41c9ac165dde0b35b8604c295772a41e' (length=32)
          public 'views' => int 2684
          public 'all_tags' => 
            array (size=0)
              ...
          public 'author' => 
            object(stdClass)[10]
              ...
          public 'has_high_quality' => boolean false
          public 'duration' => int 1340
          public 'is_adult' => int 0
          public 'thumbnail_url' => string 'http://tub.rutube.ru/thumbs-wide/a0/e9/a0e92820a935e9ddd6c077532fba3749-1.jpg' (length=77)
          public 'avatar' => string '' (length=0)
          public 'html' => string '' (length=0)
          public 'title' => string 'аватар ' (length=13)
          public 'description' => string '' (length=0)
          public 'created_ts' => string '2008-01-02T18:27:32' (length=19)
          public 'author_id' => int 0
          public 'track_id' => int 375879
          public 'aname' => string '' (length=0)
          public 'is_vip' => int 0
          public 'tv_id' => int 0
          public 'tv_title' => string '' (length=0)
          public 'season' => int 0
          public 'episode' => int 0
          public 'category_id' => int 7
          public 'is_licensed' => int 0
          public 'duration_group' => int 5
      4 => 
        object(stdClass)[11]
          public 'id' => string 'ebcd7130e5bcb81be9087495325bcd80' (length=32)
          public 'views' => int 331
          public 'all_tags' => 
            array (size=0)
              ...
          public 'author' => 
            object(stdClass)[12]
              ...
          public 'has_high_quality' => boolean false
          public 'duration' => int 1442
          public 'is_adult' => int 0
          public 'thumbnail_url' => string 'http://pic.rutube.ru/video/2b/7e/2b7ea182d936de40ea61c2f16cc9a9a6.jpg' (length=69)
          public 'avatar' => string 'user/2b/11/2b1160ed4c17b20ab3e9534bb776e212.jpg' (length=47)
          public 'html' => string '' (length=0)
          public 'title' => string 'Аватар' (length=12)
          public 'description' => string 's2e4-The Swamp.avi' (length=18)
          public 'created_ts' => string '2011-01-16T13:13:46' (length=19)
          public 'author_id' => int 17352
          public 'track_id' => int 3989416
          public 'aname' => string 'Uchiha_Itach1' (length=13)
          public 'is_vip' => int 0
          public 'tv_id' => int 0
          public 'tv_title' => string '' (length=0)
          public 'season' => int 0
          public 'episode' => int 0
          public 'category_id' => int 7
          public 'is_licensed' => int 0
          public 'duration_group' => int 5
      5 => 
        object(stdClass)[13]
          public 'id' => string '21e046d15b879c333677cd224f7f5c22' (length=32)
          public 'views' => int 41019
          public 'all_tags' => 
            array (size=1)
              ...
          public 'author' => 
            object(stdClass)[15]
              ...
          public 'has_high_quality' => boolean false
          public 'duration' => int 2731
          public 'is_adult' => int 0
          public 'thumbnail_url' => string 'http://pic.rutube.ru/video/8f/94/8f94c671495b2b479dfa57b052dd2efb.jpg' (length=69)
          public 'avatar' => string 'user/33/a1/33a1979db79e1878a9f4b0d1ce860423.jpg' (length=47)
          public 'html' => string '' (length=0)
          public 'title' => string 'Аватар: Легенда о Корре (2 книга) 1-2 серия [озв.Rain.Death]' (length=92)
          public 'description' => string 'Аватар: Легенда о Корре [ТВ-2](2 сезон) 1-2 серия русская озвучка/ Avatar: The Legend of Korra (2 книга) 1-2 серия/ Аватар: Легенда о Корре [ТВ-2](2 сезон) 1-2 серия/ Avatar: The Legend of Korra (2 книга) 1-2 серия' (length=310)
          public 'created_ts' => string '2013-09-14T21:34:27' (length=19)
          public 'author_id' => int 12034
          public 'track_id' => int 6552404
          public 'aname' => string 'D_ENIS' (length=6)
          public 'is_vip' => int 1
          public 'tv_id' => int 0
          public 'tv_title' => string '' (length=0)
          public 'season' => int 0
          public 'episode' => int 0
          public 'category_id' => int 42
          public 'is_licensed' => int 0
          public 'duration_group' => int 5
      6 => 
        object(stdClass)[16]
          public 'id' => string '561d53734809ca73f97b41613cf4a390' (length=32)
          public 'views' => int 25212
          public 'all_tags' => 
            array (size=1)
              ...
          public 'author' => 
            object(stdClass)[18]
              ...
          public 'has_high_quality' => boolean false
          public 'duration' => int 1423
          public 'is_adult' => int 0
          public 'thumbnail_url' => string 'http://pic.rutube.ru/video/a3/ad/a3ade856840ff611ccdc71fc296c7bf3.jpg' (length=69)
          public 'avatar' => string 'user/33/a1/33a1979db79e1878a9f4b0d1ce860423.jpg' (length=47)
          public 'html' => string '' (length=0)
          public 'title' => string 'Аватар: Легенда о Корре (2 книга) 8 серия [озв.Rain.Death]' (length=90)
          public 'description' => string 'Аватар: Легенда о Корре [ТВ-2](2 сезон) 8 (19) серия русская озвучка/ Avatar: The Legend of Korra (2 книга) 8 серия/ Аватар: Легенда о Корре ' (length=215)
          public 'created_ts' => string '2013-10-19T16:21:11' (length=19)
          public 'author_id' => int 12034
          public 'track_id' => int 6612374
          public 'aname' => string 'D_ENIS' (length=6)
          public 'is_vip' => int 1
          public 'tv_id' => int 0
          public 'tv_title' => string '' (length=0)
          public 'season' => int 0
          public 'episode' => int 0
          public 'category_id' => int 41
          public 'is_licensed' => int 0
          public 'duration_group' => int 5
      7 => 
        object(stdClass)[19]
          public 'id' => string '10d77328a0298537a61a616fba156814' (length=32)
          public 'views' => int 6520
          public 'all_tags' => 
            array (size=0)
              ...
          public 'author' => 
            object(stdClass)[20]
              ...
          public 'has_high_quality' => boolean false
          public 'duration' => int 1464
          public 'is_adult' => int 0
          public 'thumbnail_url' => string 'http://pic.rutube.ru/video/31/a9/31a97a6067a6f3ac545099d913c26627.jpg' (length=69)
          public 'avatar' => string 'user/33/a1/33a1979db79e1878a9f4b0d1ce860423.jpg' (length=47)
          public 'html' => string '' (length=0)
          public 'title' => string 'Аватар: Легенда о Корре 6 серия[озв.JonEA & Trina D]/ Th...' (length=86)
          public 'description' => string 'Аватар: Легенда о Корре 6 серия,Аватар: Легенда о Корре 6 серия,Аватар: Легенда о Корре 6 серия,Аватар: Легенда о Корре 6 серия,Аватар: Легенда о Корре 6 серия,Аватар: Легенда о Корре 6 серия русская озвучка,The Last Airbender: The Legend of Korra 6 серия,The Last Airbender: The Legend of Korra 6 серия,The Last Airbender: The Legend of Korra '... (length=687)
          public 'created_ts' => string '2012-05-23T13:53:24' (length=19)
          public 'author_id' => int 12034
          public 'track_id' => int 5644436
          public 'aname' => string 'D_ENIS' (length=6)
          public 'is_vip' => int 1
          public 'tv_id' => int 0
          public 'tv_title' => string '' (length=0)
          public 'season' => int 0
          public 'episode' => int 0
          public 'category_id' => int 41
          public 'is_licensed' => int 0
          public 'duration_group' => int 5
      8 => 
        object(stdClass)[21]
          public 'id' => string '7805d6304c142b090bc04c58707a9a01' (length=32)
          public 'views' => int 13909
          public 'all_tags' => 
            array (size=0)
              ...
          public 'author' => 
            object(stdClass)[22]
              ...
          public 'has_high_quality' => boolean false
          public 'duration' => int 1397
          public 'is_adult' => int 0
          public 'thumbnail_url' => string 'http://pic.rutube.ru/video/6e/8f/6e8f0937d5d36b6e276523a2df8c32a1.jpg' (length=69)
          public 'avatar' => string 'user/33/a1/33a1979db79e1878a9f4b0d1ce860423.jpg' (length=47)
          public 'html' => string '' (length=0)
          public 'title' => string 'Аватар: Легенда о Корре 4 серия[озв.4upik]/ The Last Air...' (length=86)
          public 'description' => string 'Аватар: Легенда о Корре 4 серия,Аватар: Легенда о Корре 4 серия,Аватар: Легенда о Корре 4 серия,Аватар: Легенда о Корре 4 серия,Аватар: Легенда о Корре 4 серия русская озвучка,The Last Airbender: The Legend of Korra 4 серия,The Last Airbender: The Legend of Korra 4 серия,The Last Airbender: The Legend of Korra 4 серия,The Last Airbender: The Legend of Korra 4 �'... (length=710)
          public 'created_ts' => string '2012-04-28T13:17:41' (length=19)
          public 'author_id' => int 12034
          public 'track_id' => int 5574750
          public 'aname' => string 'D_ENIS' (length=6)
          public 'is_vip' => int 1
          public 'tv_id' => int 0
          public 'tv_title' => string '' (length=0)
          public 'season' => int 0
          public 'episode' => int 0
          public 'category_id' => int 41
          public 'is_licensed' => int 0
          public 'duration_group' => int 5
      9 => 
        object(stdClass)[23]
          public 'id' => string '87b6019acda0e9f67091514d27a54eb2' (length=32)
          public 'views' => int 14972
          public 'all_tags' => 
            array (size=0)
              ...
          public 'author' => 
            object(stdClass)[24]
              ...
          public 'has_high_quality' => boolean false
          public 'duration' => int 1451
          public 'is_adult' => int 0
          public 'thumbnail_url' => string 'http://pic.rutube.ru/video/33/7b/337b3120c6e6a9b43b8f57aefee0016e.jpg' (length=69)
          public 'avatar' => string 'user/33/a1/33a1979db79e1878a9f4b0d1ce860423.jpg' (length=47)
          public 'html' => string '' (length=0)
          public 'title' => string 'Аватар: Легенда о Корре 9 серия[озв.Rain.Deat h]/ The La...' (length=86)
          public 'description' => string 'Аватар: Легенда о Корре 9 серия,Аватар: Легенда о Корре 9 серия,Аватар: Легенда о Корре 9 серия,Аватар: Легенда о Корре 9 серия,Аватар: Легенда о Корре 9 серия,Аватар: Легенда о Корре 9 серия русская озвучка,The Last Airbender: The Legend of Korra 9 серия,The Last Airbender: The Legend of Korra 9 серия,The Last Airbender: The Legend of Korra '... (length=701)
          public 'created_ts' => string '2012-06-10T21:49:28' (length=19)
          public 'author_id' => int 12034
          public 'track_id' => int 5692701
          public 'aname' => string 'D_ENIS' (length=6)
          public 'is_vip' => int 1
          public 'tv_id' => int 0
          public 'tv_title' => string '' (length=0)
          public 'season' => int 0
          public 'episode' => int 0
          public 'category_id' => int 41
          public 'is_licensed' => int 0
          public 'duration_group' => int 5
  public 'count' => int 1000
4

2 に答える 2

0

あなたはそれを正しくやっています。foreach の代わりに for ループを使用して数マイクロ秒を得ることができますが、私はそれについて心配しません。あなたは明らかにjsonファイルをダウンロードしているので、ファイルが大きすぎて「for」が「foreach」と違いを生んだ場合、おそらくダウンロードしないでしょう。同じことが結果の割り当てにも当てはまります。各一致のコピーを作成し、それを新しい配列に追加しています。大規模なデータの状況では、for ループを使用して結果配列内の各一致のインデックスを追跡するメモリ使用量が懸念される場合があります。そしてそこから行きます。しかし、繰り返しになりますが、json ファイルのダウンロードを扱っている場合、上記の問題のいずれかが発生することはないと思います。そのままにしておきます。

于 2013-11-04T01:22:40.893 に答える
0

PHP >= 5.3 の場合:

$results = array_filter($arr, function($var) {
    return $var->duration > 3600;
});

$count = count($results);
于 2013-11-04T01:51:07.600 に答える