How to Convert Boolean to String

后端 未结 15 752
死守一世寂寞
死守一世寂寞 2020-11-28 02:43

I have a Boolean variable which I want to convert to a string:

$res = true;

I need the converted value to be of the format: \"true\"

15条回答
  •  独厮守ぢ
    2020-11-28 03:20

    boolval() works for complicated tables where declaring variables and adding loops and filters do not work. Example:

    $result[$row['name'] . "" . (boolval($row['special_case']) ? 'True' : 'False') . "" . $row['more_fields'] = $tmp
    

    where $tmp is a key used in order to transpose other data. Here, I wanted the table to display "Yes" for 1 and nothing for 0, so used (boolval($row['special_case']) ? 'Yes' : '').

提交回复
热议问题