질문Q #21645
explode() expects parameter 2 to be string, array given 경고 메시지
신일2019-08-27 15:06:06

1번 $result 값을 2번에 대입 했는데, 

explode() expects parameter 2 to be string, array given 경고 메시지가 나오네요;; 

어디서 잘 못된 걸까요???  $result 은 아래와 같습니다 

Array ( [0] => stdClass Object ( [job_type] => 기획자,엔지니어 ) )




function recruit_list($mem_id)
{
    [1]
    $this->db->select('
        group_concat(DISTINCT job_type) AS job_type                                       
        ');                                                                               
    $this->db->from('profile_basic');
    $this->db->where('mem_id', $mem_id);
    $query = $this->db->get();
    $result = $query->result();                                                           

    //[2] 1번의 $result 값 콤마 기준으로 분리해서 배열로 만듬
    $array_job_type = explode( "," , $result );                                            


    //[3] 2번 값을 where_in에 대입
    $this->db->select('
        a.mem_id, b.rbs_id, 
        b.recruit_name, company_logo, job_type 
        ');
    $this->db->from('member AS a');
    $this->db->join('recruit_basic AS b','a.mem_id = b.mem_id');
    $this->db->where_in('job_type', $array_job_type);   //2번 값을 where_in에 대입    
    $query = $this->db->get();
    $result = $query->result();                                                            
    return $result;
}

 

답변3
#1 엽토군 2019-08-27 15:29:57

"explode() expects parameter 2 to be string, array given"은 번역하면 explode() 의 2번 변수가 문자열이어야 하는데 배열이 들어왔다는 겁니다. 이건 에러가 아니고 지금 하신 실수를 지적한 겁니다. 왜냐하면 지금 질문자님은 $result 말고 $result[0]->job_type 을 콤마로 구분하고 싶으신 거거든요.

$array_job_type = explode(",", $result[0]->job_type); 하셔야 원하는걸 얻으실수 있을것입니다.

#2 변종원(웅파) 2019-08-27 15:41:15
explode()이 목적이 스트링을 특정 문자로 구분하여 배열화 하는 것입니다.
#3 신일 2019-08-28 12:43:53
두분 감사하드려요^^ 덕분에 잘 해결했습니다^^