我需要帮助:))
我有一个while / loop从我的数据库中获取值。此循环将数据库值与$_POST
输入组合,并为每个项目生成$score
。
代码:
while($row=mysql_fetch_assoc($res)){
$score=($row["near_beach_score"]*$result_a)+
($row["near_city_score"]*result_b)+
($row["near_swim_pool_score"]*result_c)+
($row["near_public_transport_score"]*result_d)+
$row["house_promote_score"];
$array_content.='array('.$row["id"].', '.$score.') ';
当while / loop完成时,我希望有一个多数组,其中包含在while / loop中生成的字符串的内容。
赞:$complete_array = array ($array_content);
然后我想申请array_multisort
。
如何将$array_content
连接/插入$complete_array = array ($array_content);
?
如果您有时间帮助,请提供帮助。 /塞尔吉奥
答案 0 :(得分:1)
试试这个:
<?php
$array_content = array();
while($row=mysql_fetch_assoc($res)){
$score=($row["near_beach_score"]*$result_a) +
($row["near_city_score"]*result_b)+
($row["near_swim_pool_score"]*result_c)+
($row["near_public_transport_score"]*result_d)+
$row["house_promote_score"];
$array_content []=array($row["id"], $score);
}
您制作了String
。如果您移除'
,则会获得array
答案 1 :(得分:1)
假设id
是一个唯一字段:
$arr = array();
while ($row = mysql_fetch_assoc($res)) {
$score = ...;
$arr[$row['id']] = $score;
}
它会在键中存储$row['id']
的值,在值中存储$score
。