php array help - how to place this array inside another array? -
i have array 3 main keys. images, downloads , videos.
here's dump example:
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" } } }
in order produce i've used methods here:
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 $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 add videos here if ($this->_splitvideo($r['proof']) != false) { $arr["videos"][] = $this->_splitvideo($r['proof']); } } //eo foreach }//eo if return $arr; } /** * @desc finds video reference convert video object, finally, * store in 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] $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; } }
as can see, "images" , "downloads" associated proof records $r. videos however, aren't.
i request in order allow videos key be, integrated $r, images , downloads are, that, instead of video dump have now, have like:
["videos"]=> array(1) { [0]=> array(3) { ["cod_teamfk"]=> string(2) "51" ["bonus"]=> string(1) "0" ["attachement"]=> null ["videoobject"]=> string(17) "video object here" } }
change:
if ($this->_splitvideo($r['proof']) != false) { $arr["videos"][] = $this->_splitvideo($r['proof']); }
to:
if ($this->_splitvideo($r['proof']) != false) { $r["videoobject"] = $this->_splitvideo($r['proof']); $arr["videos"][] = $r; }
now it's question of adapting splitvideo method output video objects, instead of array.
:)
yupi!!!
Comments
Post a Comment