PHP获取键值或最大值

I'v got this array:

$by_date = array(
    "2018-10-05"=>54,
    "2018-10-07"=>20,
    "2018-10-08"=>31,
    "2018-10-12"=>52
    );

I want to get value by date, but if the date doesn't exist get the lowest date value

for example:

if the date is "2018-10-07" I'll get 20

and if the date is "2018-10-10" I'll get 31

that can go to bigger differences between the date and the last key in the array

For example, if the date is "2019-01-25" I'll get 52 because "2018-10-12" is the last key in the array.

Thanks for the help :)

查看全部
dsajkdadsa14222
dsajkdadsa14222
2018/10/17 12:43
  • php
  • arrays
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复