while 문 밖에서 변수 사용
Server Side/PHP2016. 1. 3. 19:23
$members = array(); while ($rows = $query->fetch_array()){ $members[] = $rows; } // 방법 1 for ($i = 0; $i < count($members); $i++){ echo $members[$i]['plan_subject']; echo $members[$i]['plan_content']; } // 방법 2 $members = array(); $cnt = 0; // ★ while ($rows = $query->fetch_array()){ $members[] = $rows; $cnt++; // ★ } for ($i=0,$cnt=count($members);$i<$cnt;$i++) // 방법 3 foreach( $members AS $key => $val ) { echo $val['plan_subject']; echo $val['plan_content']; }class 로 짤 때 불가피하게 사용 해야 할때가 있음.
'Server Side > PHP' 카테고리의 다른 글
array_shift 사용방법 (0) | 2016.07.29 |
---|---|
파일 업로드 레퍼런스 (0) | 2016.07.08 |
PHP 비교 연산자 (0) | 2015.10.17 |
PHP 변수를 쿼리스트링으로 처리할 때 주의사항 (0) | 2015.08.27 |
PHP 변수 Mysql 에서 되지 않을 때 (0) | 2015.07.25 |