返回10而不退出-PHP

时间:2017-03-04 06:31:27

标签: php return

<br>如果为true,则返回1。 在下面的情况中,当值为true时,它返回10 如果我把它退出正确返回1。 为什么会这样?

Ajax调用

JS -Calling AJAX

$ifvalid

PHP

var data = {
   action: "validate_date",
   start_date: 22/2/2017,
   end_date: 22/7/2017,
}; 

$.post(ajaxurl, data, function (response) {
   alert(response)
});

在这个ajax的回复中我<?php function validate_date(){ $start_date = $_POST['start_date']; $expiration_date= $_POST['end_date']; $ifValid = check_in_range($start_date, $expiration_date); echo $ifValid; //returns 10 echo $ifValid;exit; //returns 1 } function check_in_range($start_date, $end_date) { // Convert to timestamp $start_ts = strtotime($start_date); $end_ts = strtotime($end_date); $timeNow = strtotime("now"); // Check that user date is between start & end return (($timeNow >= $start_ts) && ($timeNow <= $end_ts)); } ?>

1 个答案:

答案 0 :(得分:0)

  

您可以设置如下所示的功能

function check_in_range($start_date, $end_date)
{
  // Convert to timestamp
  $start_ts = strtotime($start_date);
  $end_ts = strtotime($end_date);
  $timeNow = strtotime("now");

  // Check that user date is between start & end
  if(($timeNow >= $start_ts) && ($timeNow <= $end_ts)){
      return '1'; // OR return '0'; as you want
  }else{
      return '0'; // OR return '1'; as you want
  }
}