我有一个JSON对象数组,如下所示。文件中包含以下内容
(feed/ptp-ess_landing_house.json)
在A行提到。
{
"house_sitting_date_current_month": ["2020-02-01", "2020-02-02", "2020-02-03", "2020-02-04", "2020-02-05", "2020-02-06"],
"house_sitting_date_yes_no_current_month": ["yes", "nada", "nada", "nada", "yes", "yes"],
"house_sitting_date_next_month": ["2020-03-01", "2020-03-02", "2020-03-03", "2020-03-04", "2020-03-05", "2020-03-06"],
"house_sitting_date_yes_no_next_month": ["no", "yes", "yes", "nada", "nada", "nada"],
"toggle_status": null
}
每个特定的日期都有一个值
(是/否/nada)
与之相关。
当月
($data_house->house_sition_date_current_month)
;
2月1日
,
2月5日
和
2月6日
有
对
(其余都是娜达)。
下个月
($data_house->house_sition_date_next_month)
;
3月2日
和
3月3日
有
对
.
3月1日
是
不
(其余都是娜达)。
以下是php代码:
<?php
if (file_exists('feeds/ptp-ess_landing_house.json')) {
$data_house = json_decode(file_get_contents('feeds/ptp-ess_landing_house.json')); // Line A
}
$date = date("Y-m-d");
$sitting_day_str_en = "Sitting day";
$not_a_sitting_day_str_en ="Not a Sitting Day";
?>
<header class="entry-header container">
<?php
the_title('<h1 class="entry-title-house">', '</h1>');
?>
<span class="current-date"><?php echo $date ?></span><!-- prints today's date--> // Line B
<?php if (ICL_LANGUAGE_CODE == 'en') { ?> <!-- English -->
<span class="current-date-answer">Sitting Day</span> // Line C
<?php } ?>
</header>
问题陈述:
目前我有硬编码
休息日
在C线
我想知道我应该在上面的php代码中做些什么更改
(特别是C线)
因此
B行
外观/匹配/扫描
($data_house->house_sitting_date_current_month, $data_house->house_sitting_date_next_month)
上面JSON中的日期
并在
C行
基于
今天的日期
在
JSON
.
案例1:
如果今天的日期是
2020-02-1
在
B行
以及它的
对
对于JSON中相应的日期,则应该是在
C行
.
案例2:
如果今天的日期是
2020-03-01
在B线和它的
不
对于JSON中相应的日期,则应该说不是在
C行
.
案例3:
如果今天的日期是
2020-03-06
在
B行
和
娜达
在特定日期的JSON中存在,那么应该在
C行
.
我认为,我们需要使用两个foreach循环,但还需要做更多的工作。
<?php foreach ($data_house->house_sitting_date_current_month as $key1 => $val1) {
foreach ($data_house->house_sitting_date_yes_no_current_month as $key1 => $val1) {
}} ?>
<?php foreach ($data_house->house_sitting_date_next_month as $key2 => $val2) {
foreach ($data_house->house_sitting_date_yes_no_next_month as $key2 => $val2) {
}} ?>