有没有什么方法可以在php中声明动态变量。例如,我使用for循环,变量名为$message。我想在变量名的末尾添加一些动态数据。代码如下
foreach ($quant as $quantity) {
$message.$quantity[\'type\'] = \'Listing ID : \'.$quantity[\'product_id\'].\' With Quantity: \'.$quantity[\'quantity\'].\'MT, State- \'.$quantity[\'state_name\'].\' and Coal type-\'.$quantity[\'coal_type\'].\'<br>\';
}
因此,如果$quantity[\'type\']=1,那么变量名应该是$message1,依此类推。目前我正在尝试连接,但这是错误的。请告诉我如何更正。提前感谢