第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

與PHP中的用戶數(shù)據(jù)相比,根據(jù)范圍獲取數(shù)據(jù)

與PHP中的用戶數(shù)據(jù)相比,根據(jù)范圍獲取數(shù)據(jù)

PHP
不負(fù)相思意 2021-08-28 09:00:37
這是我的數(shù)據(jù)庫表:id      target_download     date1       10                  2019-06-182       20                  2019-06-183       30                  2019-06-184       40                  2019-06-18  如果假設(shè)用戶下載 = 15,它將在10 到 19 范圍內(nèi)計(jì)數(shù)并獲得第一行 id = 1如果假設(shè)用戶下載 = 25,它將在20 到 29 范圍內(nèi)計(jì)數(shù)并獲得第二行 id = 2所以根據(jù)用戶下載和范圍獲取數(shù)據(jù)。我想你明白我的問題。我試試這個:$=i;foreach ($datas as $key=>$val){    if($datas[$i]['targer_download'] >= $user_download && $datas[$i+1]['targer_download'] < $user_download){    }}
查看完整描述

1 回答

?
揚(yáng)帆大魚

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超9個贊

嘗試這個


$data[]['target_download'] = 10;

$data[]['target_download'] = 20;

$data[]['target_download'] = 30;

$data[]['target_download'] = 40;

$user_download = 15;

foreach($data as $key => $val) {

   if($user_download >= $val['target_download'] && $user_download < $data[++$key]['target_download']) {      

    //Do your stuff

    echo "Range is ".$val['target_download'];

  }

}

我假設(shè)您將使用數(shù)字?jǐn)?shù)組從數(shù)據(jù)庫獲取數(shù)據(jù)。


編輯 其他解決方案


    $arr = array(10, 20, 30, 40);

    function getClosest($search, $arr) {

       $a = null;

       foreach ($arr as $i) {

          $a = $search >= $i ? $i : $a;

       }

       return $a===null ? 0:$a;

    }


    echo $v = getClosest(15, $arr);


查看完整回答
反對 回復(fù) 2021-08-28
  • 1 回答
  • 0 關(guān)注
  • 129 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號