Last active
August 29, 2015 14:14
-
-
Save gabrieljmj/02a789d440101b272acc to your computer and use it in GitHub Desktop.
PHP Cenary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$images = array( | |
1 => 'https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSwN2pF0jnnNlxtNRythauTtBgtNFTSx0ucRHeKfahoo33XEtFjUEYVfnE', | |
2 => 'http://i7.photobucket.com/albums/y266/Linkforce712/SEA01.png' | |
); | |
$arr = array(1, 1, 1, 1, 1, 1); | |
$arr2 = array(1, 2, 2, 2, 2, 1); | |
$arr3 = array(1, 1, 1, 1, 1); | |
function transform($images) | |
{ | |
$arrs = func_get_args(); | |
$images = $arrs[0]; | |
$sizes = array_map(function (array $arr) { | |
return count($arr); | |
}, $arrs); | |
$bigger = max($sizes); | |
!isset($images[0]) ? $images[0] = null : null; | |
unset($arrs[0]); | |
foreach ($arrs as $key => $arr) { | |
count($arr) < $bigger ? $arrs[$key] = array_pad($arrs[$key], $bigger, 0) : null; | |
} | |
foreach ($arrs as $key => $arr) { | |
foreach ($arr as $url) { | |
$urlImg = $images[$url]; | |
$urls[$key][] = '<img width="10" height="10" src="' . $urlImg . '" />'; | |
} | |
} | |
foreach ($urls as $key => $imgs) { | |
$camps[$key] = implode('', $imgs); | |
} | |
foreach ($camps as $key => $imgs) { | |
$return[] = $imgs . '<br />'; | |
} | |
return implode('', $return); | |
} | |
echo transform($images, $arr, $arr2, $arr3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment