我试图将数组的每个值分隔在不同的变量中。$sql1 = "SELECT comp,code, MATCH (job) AGAINST ('$offer' IN BOOLEAN MODE) AS score FROM general_comp ORDER BY score DESC";$result = mysqli_query($connect, $sql1);$gen = mysqli_fetch_assoc($result);输出:数组 ( [comp] => 保险客户顾问 [code] => abc [score] => 2我想要:$comp = "Conseil clientèle en assurances";$code = "abc";$score = "2";
3 回答
小怪兽爱吃肉
TA贡献1852条经验 获得超1个赞
您可以使用extract
例如:
$array = array("color" => "blue",
"size" => "medium",
"shape" => "sphere");
extract($array);
echo $color."<br>";
echo $size."<br>";
echo $shape."<br>";
这输出:
blue
medium
sphere
鸿蒙传说
TA贡献1865条经验 获得超7个赞
但如果您想对变量名称进行二次控制,则可以使用list(). 还需要在保持自然顺序的同时array_values()获取所需的数字索引:list()
$a = array();
$a["comp"] = "Conseil clientèle en assurances";
$a["code"] = "abc";
$a["score"] = 2;
list($comp, $code, $score) = array_values($a);
echo $comp . ", ";
echo $code . ", ";
echo $score;
输出:
Conseil clientèle en assurances
abc
2
达令说
TA贡献1821条经验 获得超6个赞
您可以循环遍历数组,并将值转换为字符串,如下所示:
foreach ($array as $key => $value) {
$array[$key] = strval($value);
}
现在你的数组元素都是字符串。
- 3 回答
- 0 关注
- 120 浏览
添加回答
举报
0/150
提交
取消