如何通过一组数组循环条件以返回true的值

I have a textarea that submits text which is converted to an array using the explode function, then the values of that array is made into individual arrays within a foreach loop. This is the function

The text area entry
mon|0000|0500|The Morning Blast|sally.jpg|DJ Sally
---
mon|0500|1000|Day Time Soap|wally.jpg|Wally

The processing code

$itemlist = trim(preg_replace('/
/', '', $itemlist ));
$itemlist = explode('---', $itemlist);

$dow = strtolower(date( 'D' ));
$tod = date( 'Hi' );

foreach($itemlist as $items) {
//this creates 2 arrays with 6 keys each
//array([0]=>mon[1]=>0000[2]=>0500[3]=>The Morning Blast[4]=>sally.jpg[5]=>DJ Sally)
//array([0]=>mon[1]=>0500[2]=>1000[3]=>Day Time Soap[4]=>wally.jpg[5]=>Wally)

$itempart = explode('|', $items);

if($itempart[0] == $dow && $tod >= $itempart[1] && $tod <= $itempart[2] ) {
?>

<div>
<h4><?php echo $itempart[3]; ?></h4>
<p><?php echo $itempart[5]; ?></p>
<img src="<?php echo $itempart[4]; ?>" />
</div>

<?php } 
}//endforeach ?>

The problems
The condition which checks the day of week and time of day, processes only the first array and correctly returns the output HTML, but once the time expires and it is then false, the subsequent array is not processed even though it is true.

The logic seems correct but it just won't work. What is needed to make this scan the list of arrays and return only the one that is true?

查看全部
duangong1979
duangong1979
2014/11/28 09:16
  • foreach
  • php
  • arrays
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复