컨트롤러에서 heredoc 구문과 관련된 문제가 있습니다.foreach 루프에서 php heredoc 구문을 사용하는 방법
function active() {
$userlist = $this->input->post('userlist');
$userlist = explode(',',$userlist[0]);
$items = '';
if(!empty($userlist)){
foreach($userlist as $buddy)
{
$actv = $this->user_model->check_active_users($buddy);//returns 0 if no results found
if ($online_buddies == 0) {
$items .= <<<EOD
{
"fl": "0",
"fid": "{$buddy}"
},
EOD;
}//if returned 0 inactive
}//foreach
}//if nt empty $mybuddies
if ($items != '')
{
$items = substr($items, 0, -1);
}
header('Content-type: application/json');
?>
{
"items": [
<?php echo $items;?>
]
}
<?php
exit(0);
}//end of func active
$userlist
가 user-ids
보유 : 내 컨트롤러 기능은 다음과 같이한다.
$this->user_model->check_active_users($buddy)
결과가없는 경우 0을 반환합니다.
각 사용자 ID뿐만 아니라 데이터베이스에 결과가없는 경우 플래그 0
을 얻고 싶습니다.
그러나, 여기
$items .= <<<EOD
{
"fl": "0",
"fid": "{$buddy}"
}
EOD;
, fl
반환 0
하지만 fid
아무것도 반환하지 않습니다. 내가 잘못한 일을 했습니까? "fid": "{$buddy}"
을 대신 문자열을 조작, 당신은'()로 json_encode'에 의해 네이티브 PHP 배열의 출력 최종 결과를 사용하여 시도해야한다; –
탱크가 많습니다 ..... – user3177114