如何将变量插入正在创建的新变量中? 我将之前创建的$ array [0]插入$ txt。 我该怎么办?
致谢
$conn = new mysqli("localhost","user","pass","db");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sets = "SELECT grp_phone FROM groups WHERE grp_onoff='YES'ORDER BY id ASC";
if ($result = mysqli_query($conn,$sets)){
$array = array();
while($r = mysqli_fetch_array($result))
$array[] = $r[0];
}
$group = fopen("/tmp/group_70000.txt", "w+") or die("Unable to open file!");
$txt = 'SET Station_Group "1": "1": "70000"
{
Attached_Stations = {".$array[0]"}
}';
fwrite($group, $txt);
fclose($group);
$conn->close();```
答案 0 :(得分:0)
通过{" '.$array[0] .' "}
,您将获得所需的价值。
看看
<?php
$array[0] = "100";//example
$txt = 'SET Station_Group "1": "1": "70000"
{
Attached_Stations = {" '.$array[0] .' "}
}';
echo $txt;
你得到
SET Station_Group "1": "1": "70000"
{
Attached_Stations = {" 100 "}
}