duanliao6789 2011-04-04 22:10
浏览 28

为什么php的行为与我明确设置值时的行为不一样?

I have tried the same code both ways, it works the first way, when I do it the second way, it doesn't error, but just appears to do nothing.

I'm getting some values (two dates) in a View in Drupal. I can print the values and get EXACTLY the same values as I have set explicitly. I've tested this using print.

Although the values using print are identical to those i've set explicitly, it's not working with the data pulled from Drupal.

Example of printing:

$fields['field_deal_from_value']->content;

//The result from this is that it prints the following:

2011-04-24

Version 1 - Working with explicitly set value

<?php
$pastDateStr = "2011-04-24"; 
$pastDateTS = strtotime($pastDateStr); 

for ($currentDateTS = $pastDateTS; $currentDateTS <= strtotime("2011-05-28");$currentDateTS += (60 * 60 * 24)) { 
// use date() and $currentDateTS to format the dates in between 
$currentDateStr=date("d-m-Y",$currentDateTS); 
print $currentDateStr."<br/>"; 
}
?>

Version 2 - Not Working - Values are definitely set correctly

<?php
$pastDateStr = $fields['field_deal_from_value']->content; 
$pastDateTS = strtotime($pastDateStr); 

for ($currentDateTS = $pastDateTS; $currentDateTS <= strtotime($fields['field_deal_to_value']->content); $currentDateTS += (60 * 60 * 24)) { 
// use date() and $currentDateTS to format the dates in between 
$currentDateStr=date("d-m-Y",$currentDateTS); 
print $currentDateStr."<br/>"; 
}
?>
  • 写回答

4条回答 默认 最新

  • douyin2883 2011-04-04 22:15
    关注

    You should turn error reporting all the way so you can see warnings.
    I suspect you'll see an error saying that the result of $fields['..']->content cannot be used in a write context (ie as the argument of strtotime).
    I'd try to save the value of $fields['..']->content in a variable and use that variable in the loop's condition.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题