duanjurong1347 2011-03-24 02:44
浏览 51
已采纳

使用PHP计算基于JSON数组中的出生日期信息的一个年龄

I was wondering how I could use PHP to calculate one's age given a date string with values from a JSON array:

{  
    "DOB":{ // should I use integers or strings for these values? I'm assuming strings for now.  
        "year": "1970",  
        "month": "01",  
        "day": "01"  
    }  
}

How would I then use PHP to calculate the age?
Additionally, say all of this information is a small part of something like a staff directory, with the format of { "People":{ "user1":{ label: value },"user2":{ label: value} } }. How could I use PHP to create <label> tags for label within <li> tags for value (<li><label>label</label>value</li>) within unordered lists for each user within divs for each user?
Please tell me if this is confusing; and the calculation of the age is my highest priority right now.

  • 写回答

3条回答 默认 最新

  • duan7772 2011-03-24 03:05
    关注

    Not sure if I correctly understood what you're trying to do with the user so let me know if i was mistaken:

    <?php
        $people = json_decode($data);
    ?>
    <html>
        <head>
            <title>Users List</title>
        </head>
    <body>
        <?php foreach ($people as $userName => $userInfo): ?>
        <div>
            <p><?php echo $userName; ?>
            <ul>
            <?php foreach ($userInfo as $label => $value): ?>
                <li><label><?php echo $label; ?></label> <?php echo $value; ?></li>
            <?php endforeach; ?>
            </ul>
        </div>
        <?php endforeach; ?>
    </body>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度