輸出爲$狀態PHP - 字符串替換語法錯誤:非法字符
Array
(
[1] => 1
[2] => 0
[3] => 0
[4] => 4
[5] => 4
)
$color_code_string = implode(",",$status);
輸出繼電器
1,0,0,4,4
$color_code_string = str_replace("0","'#F00'",$color_code_string);
$color_code_string = str_replace("1","'#00bcd4'",$color_code_string);
$color_code_string = str_replace("2","'#4caf50'",$color_code_string);
$color_code_string = str_replace("3","'#bdbdbd'",$color_code_string);
$color_code_string = str_replace("4","'#ff9900'",$color_code_string);
異常
SyntaxError: illegal character
colors: ['#00bcd'#ff9900'','#F00','#F00','#ff9900','#ff9900']
//prints '#00bcd'#ff9900'','#F00','#F00','#ff9900','#ff9900'
如何實現預期的輸出如下
'#00bcd','#ff9900','#F00','#F00','#ff9900','#ff9900'