检查变量是否高于数组php

时间:2016-04-08 16:28:07

标签: php arrays compare

我想检查变量是否大于或等于数组中的项。

我尝试了多个for循环,但之后它们只是堆叠,堆叠和堆叠。我只需要获取日期,例如:01-01-2005 / 01-01-2006 并将这两者与今天的日期进行比较,并检查今天的日期是否大于或等于书的日期。如果这本书比较旧,那么今天的日期会做一些代码

foreach ($user_out as $userOut) {
    $userOut_id[] = $userOut['user_id'];
    }
    $userOut_id_implode = implode(',',$userOut_id);
//loop through each element from the tocomet able
$dateOfBook = [];
$today = date("d-m-Y");
foreach ($out as $outs) {
    $datum = $outs['released'];

    //gets the date of the selected book.
    $bookDate = date("d-m-Y", strtotime($datum));
    $dateOfBook[] = $outs['released'];

    //gets the name of the author
    $author_name = $outs['author'];

    //gets the title of the book
    $book_title = $outs['book_title'];

    $today = strtotime($today);
    $bookDate = strtotime($bookDate);
    //checks if today is equal or smaller then the bookdate 

}
$today = date("Y-m-d");
$y = count($dateOfBook);

for($x = 0; $x < $y; $x++){
    echo $x;
};

if($today >= $dateOfBook($x)){
    do stuff
}

1 个答案:

答案 0 :(得分:0)

$dateOfBook = [];
$today = date("d-m-Y");
$flag = 0;
foreach ($out as $outs) {

    //gets the date of the book out of the database 
    if($today >= $outs['released']){
        $flag++;
    }
    $dateOfBook[] = $outs['released']; # is this necessary?
}

if($flag){
   # do something
}