zoukankan      html  css  js  c++  java
  • php 渣全的循环

    <?php
    // echo strtotime("2018-04-01 17:56").'<br/>';
    // echo strtotime("2018-05-31 17:56");
    header("content-type:text/html;charset=utf-8");

    $arr = array(
    array(
    'count_num' =>'71',
    'new_time' =>'04.12',
    ),
    array(
    'count_num' =>'1647',
    'new_time' =>'04.13',
    ),
    array(
    'count_num' =>'149',
    'new_time' =>'04.14',
    ),
    array(
    'count_num' =>'94',
    'new_time' =>'04.15',
    ),
    array(
    'count_num' =>'194',
    'new_time' =>'04.17',
    ),

    );

    $a = array(
    '04.17',
    '04.16',
    '04.15',
    '04.14',
    '04.13',
    '04.12',
    '04.11',
    );

    /**
    *查询结果处理
    *$arr是数据库查询出来的结果集合
    *$a是日期
    */
    function test($arr,$a){
    $star_names = array_column($arr, 'count_num');
    $last_names = array_column($arr, 'new_time');
    $trans = array_flip($last_names);
    for($i = 0;$i < count($a);$i++){
    if(in_array($a[$i],$last_names)){
    $result[] = $star_names[$trans[$a[$i]]];
    }else{
    $result[] = 0;
    }
    }
    return $result;
    }
    $a = test($arr,$a);
    var_dump($a);

  • 相关阅读:
    mysql外键添加error1215
    shell命令获取最新文件的名称
    centos7 apache提供文件下载
    centos7 时间设置
    微服务通信的类型
    angular-cli
    npm
    模块相关
    加油!冲冲冲
    软件评测
  • 原文地址:https://www.cnblogs.com/ayanboke/p/8949685.html
Copyright © 2011-2022 走看看