2011-02-13 99 views
0

我有這個數組有3個主鍵。 圖片,下載和視頻。PHP數組幫助 - 如何將這個數組放在另一個數組中?

這裏是一個轉儲例如:這裏

array(3) { 
["images"]=> 
    array(1) { 
    [0]=> 
    array(3) { 
     ["cod_teamFk"]=> 
     string(2) "51" 
     ["attachement"]=> 
     string(22) "210111011642_51_57.jpg" 
     ["bonus"]=> 
     string(1) "0" 
    } 
} 
["downloads"]=> 
    array(1) { 
    [0]=> 
    array(3) { 
     ["cod_teamFk"]=> 
     string(2) "51" 
     ["attachement"]=> 
     string(22) "210111011732_51_23.zip" 
     ["bonus"]=> 
     string(1) "0" 
    } 
} 
["videos"]=> 
    array(1) { 
    [0]=> 
    array(1) { 
     ["youtube"]=> 
     array(1) { 
     [0]=> 
     string(150) "object video" 
     } 
    } 
} 

爲了製作這個我用這些方法:

function SplitProof($proof) { 

       $arr = array(); 
      $arr["images"] = array(); 
      $arr["downloads"] = array(); 
       $arr["videos"] = array(); 
      $arrDownloads = array("zip"=>1, "rar"=>1, "pdf"=>1,"doc"=>1,"docx"=>1,"ppt"=>1,"pptx"=>1); 
      $arrImagem = array("jpg"=>1,"jpeg"=>1, "gif"=>1,"png"=>1); 



      if (count($proof)) 
       { 
        foreach ($proof as $r) 
        { 

         $file = "./lib/teams/".$r["attachement"]; 

         if (is_file($file)) 
         { 
          $pathinfo = pathinfo($file); 
          $ext = strtolower($pathinfo["extension"]); 

          if ($arrImagem[$ext] == 1) 
          { 
           $fileThumb = "./lib/teams/thumb".$r["attachement"]; 

           if (!file_exists($fileThumb)) 
           { 
            $thumb = new Thumbnail("lib/teams/".$r["attachement"]); 
            $thumb->cropFromCenterNoSquare(230, 153); 
            $thumb->show(100,$fileThumb); 
           } 

           $arr["images"][] = $r; 
          } 

          if ($arrDownloads[$ext] == 1) 
          { 
           $arr["downloads"][] = $r; 
          } 

         } 

    // ISSUE HERE - DON'T KNOW HOW TO PROPERLY ADD THOSE VIDEOS HERE 
         if ($this->_splitVideo($r['proof']) != false) 
         { 
          $arr["videos"][] = $this->_splitVideo($r['proof']); 
         } 
        } //eo foreach 

       }//eo if 

       return $arr; 
      } 


       /** 
       * @desc Finds a video reference a convert it into a video object, finally, 
       * store in into an array. 
       * 
       * @param <type> $proof 
       * @return string 
       */ 
       private function _splitVideo($proof) { 


        $video_links = array(); 

        if (preg_match_all("'(http://)?(www\.)?(youtube|vimeo|videos\.frog)\.([a-z0-9_/?&+=.]+)'is",$proof,$n)) 
        { 

         foreach ($n[3] as $key => $site) 
         { 

          $urlCorreto[$key] = str_replace(array("http://www.","http://", "www."),"",$n[0][$key]); 

          $urlCorreto[$key] = "http://" . $urlCorreto[$key]; 

          $data = parse_url($urlCorreto[$key]); 

          switch(strtolower($data['host'])) 
          { 
           case "youtube.com": 

            parse_str($data["query"],$result); 

            $videoId = $result["v"]; 

            $objetoYoutube = '<iframe title="YouTube video player" width="380" height="225" src="http://www.youtube.com/embed/'.$videoId.'" frameborder="0" allowfullscreen></iframe>'; 

            $video_links[$site][] = $objetoYoutube; 

           break; 


           case "vimeo.com": 

            $vimeoPath = $data["path"]; 

            $objetoVimeo = '<iframe src="http://player.vimeo.com/video'.$vimeoPath.'" width="380" height="225" frameborder="0"></iframe>'; 

            $video_links[$site][] = $objetoVimeo; 

           break; 


           case "videos.frog.es": 

            $frogPath = $data["path"]; 

            $objetofrog = '<embed src="http://rd3.videos.frog.es/play?file=http://rd3.videos.frog.es'.$frogPath.'/mov/1" type="application/x-shockwave-flash" allowFullScreen="true" width="380" height="225"></embed>'; 

            $video_links[$site][] = $objetofrog; 

           break; 
          } 




         } 

         return $video_links; 

        } else { 

         return false; 
        } 

       } 

正如你所看到的,「圖像」和「下載」關聯帶有證據記錄$ r。但是,不是。

我想請求您的幫助,以便讓視頻鍵與$ r集成在一起,就像圖像和下載一樣,這樣我就可以擁有一些東西像這樣:

["videos"]=> 
    array(1) { 
    [0]=> 
    array(3) { 
     ["cod_teamFk"]=> 
     string(2) "51" 
     ["bonus"]=> 
     string(1) "0" 
     ["attachement"]=> 
     NULL 
     ["videoObject"]=> 
     string(17) "video object here" 
    } 
} 

回答

1

變化:

if ($this->_splitVideo($r['proof']) != false) 
{ 
    $arr["videos"][] = $this->_splitVideo($r['proof']); 
} 

到:

if ($this->_splitVideo($r['proof']) != false) 
{ 
    $r["videoObject"] = $this->_splitVideo($r['proof']); 
    $arr["videos"][] = $r; 
} 

現在,這只是一個適應splitVideo方法的問題,只輸出視頻對象,而不是數組。

:)

雨披!

相關問題