我有一个多维数组,它是这样的:
Array
(
[Monday] => Array
(
[open] => 05.00 PM
[close] => 04.00 PM
[state] => 0
)
[Tuesday] => Array
(
[open] =>
[close] =>
[state] => 1
)
[Wednesday] => Array
(
[open] => 03.00 AM
[close] => 06.00 PM
[state] => 0
)
[Thursday] => Array
(
[open] =>
[close] =>
[state] => 1
)
[Friday] => Array
(
[open] => 05.00 PM
[close] => 03.00 PM
[state] => 0
)
[Saturday] => Array
(
[open] => 05.00 PM
[close] => 06.00 PM
[state] => 0
)
[Sunday] => Array
(
[open] =>
[close] =>
[state] => 1
)
)
使用这个数组我想创建这样的输出:
Monday - 05.00 PM - 04.00 PM
Tuesday - Closed
Wednesday - 03.00 AM - 06.00 PM
Thursday - Closed
Friday - 05.00 PM - 03.00 PM
Saturday - 05.00 PM - 06.00 PM
Sunday - Closed
我尝试了 2 个 foreach 循环,但我无法让它显示预期的输出。
foreach ($result as $days => $values) {
echo "$days";
foreach ($values as $k) {
echo " - $k";
}
echo "<br/>";
}
它的输出类似于:
Monday - 05.00 PM - 04.00 PM - 0
Tuesday - - - 1
Wednesday - 03.00 AM - 06.00 PM - 0
Thursday - - - 1
Friday - 05.00 PM - 03.00 PM - 0
Saturday - 05.00 PM - 06.00 PM - 0
Sunday - - - 1
谁能告诉我我该如何解决这个问题?
注意:如果state = 0
它不需要显示,state = 1
它应该是Closed