如何从循环中的匹配值获取下一个值。数组中需要'1010-1040'键。
<?php
$arr = Array
(
'0900-0930' => 0,
'0935-1005' => 0,
'1010-1040' => 0,
'1045-1115' => 0
);
$matchVal = '0935-1005';
foreach ($arr as $key => $value) {
if($matchVal == $key){
echo $key.'<br />';
}
echo next($arr);
}
?>
提前致谢。
答案 0 :(得分:1)
<?php
$arr = Array
(
'0900-0930' => 0,
'0935-1005' => 0,
'1010-1040' => 0,
'1045-1115' => 0
);
$keys = array_keys($arr);
$matchVal = '0935-1005';
$matched = array_search($matchVal, $keys); // $key = 1;
$nextindex = $matched + 1;
$nextValue = $arr[$nextindex];
?>
答案 1 :(得分:1)
试试这个
$arr = Array
(
'0900-0930' => 0,
'0935-1005' => 0,
'1010-1040' => 0,
'1045-1115' => 0
);
$matchVal = '0935-1005';
$keys = array_keys($arr);
print $keys[array_search($matchVal,$keys)+1];
<强>输出强>
1010-1040
答案 2 :(得分:1)
请试一试。
var message = "";
if(...)
message = "....";
else if(..)
message = "//"
MessageBox.Show(message);