如何通过比较值从while语句中选择特定数据?

时间:2018-06-05 22:53:40

标签: php

标题几乎是不言自明的。我试图通过比较值并从我可以与jQuery一起使用的数组中返回计划详细信息,从while语句中选择一个特定的计划。

$compareme = some integer;

while($plan = mysqli_fetch_assoc($resultplans)) {

$finalpricing = round($plan['price']);
$planname = $plan['name'];
$plandescription = $plan['description']'

if($compareme == $finalpricing){

//select the plan with the same pricing as $compareme
 //create json array that can be used with jQuery
  $planArray = array(
                      'planName' => $planname,
                      'planPrice' => $finalpricing,
                      'planDescription' => $plandescription
                    );
  //encode in json
  header('Content-Type: application/json');
  echo json_encode($planArray);  
}
} <-- end of while loop-->

现在让我们假设两个计划A和B以相同的价格返回。有没有办法只选择一个计划?选择哪一个并不重要。我只需要退一个。

1 个答案:

答案 0 :(得分:0)

/tmp/foo.bar.gz /tmp/foo.bar 之后添加break ;,它将退出您的while循环。

echo json_encode($planArray);