我正在尝试使用set @thisdate = (
select te_date from (
select row_number() over (partition by te_system_ref order by (select 0)) as rownumber, te_date from ticket_events where te_system_ref in
(select sl_system_ref from statutory_letter where sl_letter_batch = 9429)and te_event = 'Copy of NtO produced'
) t
where rownumber = 1
);
将php“ if”重复20次。我该怎么办?
dh_c_01_01
最多20次
答案 0 :(得分:0)
我不确定我是否正确理解了您的问题,或者不确定我知道您的变量是什么或变量的值是什么。
根据您的问题,本示例使用了额外的变量for loops和动态变量。它还假定您的每个dynamic variables存在:
<?php
$dh_c_limit = 20; // <-- loop limit
$a_c_a_limit = 9; // <-- loop limit
$a_b_s_addition = 5; // <-- based on your question
$a_c_a_max = 0; // <-- change this to whatever '$a_c_a_max' should be!
for ($dh_i = 1; $dh_i <= $dh_c_limit; $dh_i++) {
if(${"dh_c_".str_pad($dh_i,2,"0",STR_PAD_LEFT)."_01"}['id'] == $a_c_a_max){ // <-- checks against '$a_c_a_max'
${"dh_sq_".str_pad($dh_i,2,"0",STR_PAD_LEFT)."_01"} = ${"a_b_s_".str_pad($a_c_i,2,"0",STR_PAD_LEFT)}; // <-- set the '$dh_sq_' variable to '$a_b_s_' variable
}
else{
for ($a_c_i = 1; $a_c_i <= $a_c_a_limit; $a_c_i++) {
if(${"dh_c_".str_pad($dh_i,2,"0",STR_PAD_LEFT)."_01"}['id'] == ${"a_c_a_".$a_c_i."_b"}){ // <-- checks against '$a_c_a_' variable
${"dh_sq_".str_pad($dh_i,2,"0",STR_PAD_LEFT)."_01"} = ${"a_b_s_".str_pad(($a_c_i+$a_b_s_addition),2,"0",STR_PAD_LEFT)}; // <-- set the '$dh_sq_' variable to '$a_b_s_' variable
break; // <-- break the loop
}
}
}
}
?>
答案 1 :(得分:-1)
那是个坏习惯。尝试使用开关盒,或使用数组作为容器
$array = [
'id1' => 'action1',
'id2' => 'action2',
...
];
$dh_sq_02_01 = $array[$dh_c_02_01['id']];
只是示例。希望有帮助