使用 str_replace 和两个组合变量

working with str_replace with two combined variables

我有这两个组合的变量

${$monthNamelower . $category[$k]}= $row['COUNT(mycategory)'];//example output decStationery

如果我的$category[$k]超过两个字

电器示例

如何使用 str replace 删除 space,使其成为

ElectricalApplicance 而不是电器?

您可以使用preg_replace 就这样

$category[$k] = preg_replace('/\s+/', '', $category[$k]);