Skip to content

Instantly share code, notes, and snippets.

@gabrieljmj
Last active August 29, 2015 14:14
Show Gist options
  • Save gabrieljmj/02a789d440101b272acc to your computer and use it in GitHub Desktop.
Save gabrieljmj/02a789d440101b272acc to your computer and use it in GitHub Desktop.
PHP Cenary
$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