如何传递增量类型抛出变量,如下面的示例:
function next_prev_elem($step_id, $array, $incre){
foreach ($array as $i) {
$incre.$step_id;
foreach ($array as $item) {
if($step_id === $item['id']){
return $step_id;
break;
}
}
}
return false;
}
$prev_id = next_prev_elem($id, $page_news, '--');
$next_id = next_prev_elem($id, $page_news, '++');
答案 0 :(得分:0)
function next_prev_elem($step_id, $array, $incre){
foreach ($array as $i) {
switch( $incre ) {
case '++':
$step_id++;
break;
case '--':
$step_id--;
break;
}
foreach ($array as $item) {
if($step_id === $item['id']){
return $step_id;
break;
}
}
}
return false;
}
$prev_id = next_prev_elem($id, $page_news, '--');
$next_id = next_prev_elem($id, $page_news, '++');
答案 1 :(得分:0)
感谢@Marc B,我最终得到了这个解决方案:
function next_prev_elem($step_id, $array, $step){
foreach ($array as $i) {
$step_id = $step_id + $step;
foreach ($array as $item) {
if($step_id === $item['id']){
return $step_id;
break;
}
}
}
return false;
}
$prev_id = next_prev_elem($id, $page_news, -1);
$next_id = next_prev_elem($id, $page_news, 1);