例えば「受付中/あとわずか/締め切り」のようなステータスを配列で取得し、$conditions
という変数にまとめて管理したい場合、if文を使って以下のように処理を行うのがスマートなのでしょうか。
lang
1// 配列 2$entries = []; 3$entries[] = [ 4 [1] => [ 5 'conditions_ok' => '受付中'; 6 'conditions_few' => ''; 7 'conditions_ok' => ''; 8 ] 9 [2] => [ 10 'conditions_ok' => ''; 11 'conditions_few' => 'あとわずか'; 12 'conditions_ok' => ''; 13 ] 14 [3] => [ 15 'conditions_ok' => ''; 16 'conditions_few' => ''; 17 'conditions_ok' => '締め切り'; 18 ] 19] 20 21// 処理 22foreach($entries as $value) { 23 $conditions = $value['conditions_ok']; 24 if ($conditions == ""){ 25 $conditions = $value['conditions_few']; 26 } 27 if ($conditions == ""){ 28 $conditions = $value['conditions_full']; 29 } 30}
ご教授いただけますと幸いです。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/12/15 01:13