이런 3단 구조의 foreach 반복문은 없나요?
본문
2단 배열까지는 되던데, 3단 이상은 이런 구조로 사용 못 하나요?
$img = array(
G5_THEME_URL."/img/01.png" => "http://www.homzzang.com/b/html" => "_blank",
G5_THEME_URL."/img/02.png" => "http://www.homzzang.com/b/css" => "_blank",
G5_THEME_URL."/img/03.png" => "http://www.homzzang.com/b/js" => "_blank",
G5_THEME_URL."/img/04.png" => "http://www.homzzang.com/b/sql" => "_blank",
G5_THEME_URL."/img/05.png" => "http://www.homzzang.com/b/php" => "_blank",
G5_THEME_URL."/img/06.png" => "http://www.homzzang.com/b/builder" => "_blank",
G5_THEME_URL."/img/07.png" => "http://www.homzzang.com/b/builder" => "_blank",
G5_THEME_URL."/img/08.png" => "http://www.homzzang.com/bbs/write.php?bo_table=order" => "_blank"
);
//shuffle($img); // 랜덤 출력
?>
<?php foreach ($img as $i => $s => $t) { ?>
<li><a href="<?php echo $s?>" target="<?php echo $t?>"><img src="<?php echo $i?>"></a></li>
<?php } ?>
답변 1
$img = array(
G5_THEME_URL."/img/01.png" => array("http://www.homzzang.com/b/html" => "_blank"),
G5_THEME_URL."/img/02.png" => array("http://www.homzzang.com/b/css" => "_blank")
);
foreach($img as $k => $v) {
foreach($v as $key => $value) {
echo "<li><a href='".$key."' target='".$value."'><img src='".$k."'></a></li>";
}
}
중간에 생략했습니다.
!-->