我制作一个剧本,但我没有正确的方法如何制作它
代码:
function ID_Photo_TMB( $ID ) {
$Images_TMB_Data = array(
'tmb' => array(
'Max' => '105296',
'Min' => '73296',
),
'tmb3' => array(
'Max' => '73295',
'Min' => '42966',
),
'tmb2' => array(
'Max' => '42965',
'Min' => '1',
),
);
}
让我们说$ ID = 32332我怎么能让函数返回tmb(数字)在最大/最小tmb或tmb2或tmb3之间的ID是什么
答案 0 :(得分:2)
foreach ($Images_TMP_Data as $key => $value) {
if ($ID >= $value['Min'] && $ID <= $value['Max']) {
return $key;
}
}
答案 1 :(得分:2)
我扩展了您的功能,以包含满足您要求所需的代码。
function ID_Photo_TMB( $ID ) {
$Images_TMB_Data = array(
'tmb' => array(
'Max' => '105296',
'Min' => '73296',
),
'tmb3' => array(
'Max' => '73295',
'Min' => '42966',
),
'tmb2' => array(
'Max' => '42965',
'Min' => '1',
),
);
foreach ($Images_TMB_Data as $key => $val) {
if ($ID >= $val['Min'] && $ID <= $val['Max']) return $key;
}
}