大きい構造情報を扱うことが多いのですが、その折連想配列の階層が深いためプログラムでそれを利用する際に
2重for文になってしまうことがあるのですが、綺麗に書く方法はありませんでしょうか?
つどforeachのネストは見づらいので何とかならないかと考えています。
$_list_data = array(); $_desc = array(); $i = 0; foreach ($_history_data as $key => $value) { $_type = null; $_conv_date = null; foreach ($value as $_history_key => $_history_value) { if ($_history_key === '_time') { $_conv_date = str_replace('-', '/', substr($_history_value, 0, 10)) . $this->_format_week(substr($_history_value, 0, 10)) . substr($_history_value, 10, 6); } if ($_history_key === '_type') { $_type = $_history_value; } if ($_history_key === '_info') { $_history_key = $this->_conv_info($_type, $_history_value); if (empty($_history_key)) { continue; } if (!empty($_conv_date)) { $_history_key['date'] = $_conv_date; } $_list_data[$i] = $_history_key; $_desc[$i] = $_history_data[$key]["_seq"]; i++; } } }
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/03/27 09:48