배열 질문드립니다.

배열 질문드립니다.

QA

배열 질문드립니다.

답변 4

본문


if($list[$i][wr_55]){
    $nots = explode('||',$list[$i][wr_55]);
    $notsname = explode('||',$list[$i][wr_12]);

    for($k=0; $k<count($nots); $k++){
        echo $nots[$k]; 
    }
}

 

wr_55 의 값중에 D값을 제외 출력하고 싶습니다.

예를들어 

wr_55   의 값이   Y||D||Y||Y||D

일때  

1, 3, 4번째 값만 출력하고 이 순서대로 wr_12의 값중에 해당 순번만 뿌려주고 싶은데

어떻게 해야 할지 모르겠습니다.

 

 

이 질문에 댓글 쓰기 :

답변 4

if($list[$i][wr_55]){
    $nots = explode('||',$list[$i][wr_55]);
    $notsname = explode('||',$list[$i][wr_12]);

    for($k=0; $k<count($nots); $k++){
            if( $k==1) continue;
        echo $nots[$k]; 
    }
}


    for($k=0; $k<count($nots); $k++){
        echo $nots[$k]; 
    }

이부분에



    for($k=0; $k<count($nots); $k++){
        if($nots[$k] != "D"){
           echo $nots[$k]; 
         }
    }

이렇게 예외처리를 하시면 되지 않을까요 ?

if($list[$i][wr_55]){
    $nots = explode('||',$list[$i][wr_55]);
    $notsname = explode('||',$list[$i][wr_12]);

    for($k=0; $k<count($nots); $k++){
        if ($nots[$k] == 'Y') echo $notsname[$k];
    }
}

if($list[$i]['wr_55']){
    $nots = explode('||', $list[$i]['wr_55']);
    $notsname = explode('||', $list[$i]['wr_12']);
    foreach ($nots as $key=>$value) {
        if($value!=='Y') continue;
        echo $notsname[$key];
    }
}

+ foreach

- https://www.php.net/manual/en/control-structures.foreach.php

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 234
© SIRSOFT
현재 페이지 제일 처음으로