Post

문자 및 변수명 조합으로 가변변수 만들기

1
${"brand_list".$j}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
  for($j=1; $j<10; $j++){
    $brand_array = ${"brand_list".$j};  //   배열명
    for($i=0; $i<count($brand_array); $i++){   
?>
<li class="brand__item">
  <a href="#">
    <div class="photo"><img src="<?=$brand_array[$i]['brandimg']?>" alt="<?=$brand_array[$i]['brandttl']?>"></div>
    <p><?=$brand_array[$i]['brandttl']?></p>
  </a>
</li>
<?php
    }
  }
?>
This post is licensed under CC BY 4.0 by the author.