PHP条件循环帮助

sea*_*987 1 php conditional

您好我的数据库中有3列,is_contract,is_permenant和is_temporary.在这些列中,有Y或N值.

我正在使用这些列回显到页面上有人正在寻找什么样的工作,我的问题是用户可以查找多种类型的工作,我目前正在运行3 if语句以确定要回应的内容页面,但是我很难添加一个逗号,如果多个statemnts返回为true,下面是我的代码到目前为止,

<?php
    if($rslt['is_contract'] == 'Y') {
        echo "Contract ";
}
    if($rslt['is_permanent'] == 'Y') {
        echo "Permanent ";
}
if($rslt['is_temporary'] == 'Y') {
    echo "Temporary";
}
?>
Run Code Online (Sandbox Code Playgroud)

You*_*nse 5

<?php
    $out=array();
    if($rslt['is_contract'] == 'Y') $out[]="Contract";
    if($rslt['is_permanent'] == 'Y') $out[]="Permanent";
    if($rslt['is_temporary'] == 'Y') $out[]="Temporary";
    echo implode(", ",$out);
?>
Run Code Online (Sandbox Code Playgroud)