extract values from array (php or jquery)

梦想与她 提交于 2019-12-13 02:28:00

问题


I've got an array like this:

Array
(
    [username] => myusername
    [created_at] => 2013-01-01 15:30:27
    [public_id] => aaabbbccc112233
    [reputation] => 16
    [hourly_quota] => 256
    [backlog] => 32
    [stats] => Array
        (
            [today] => Array
                (
                    [sent] => 43
                    [hard_bounces] => 556
                    [soft_bounces] => 64
                    [rejects] => 36
                    [complaints] => 123
                    [unsubs] =>45
                    [opens] => 36
                    [unique_opens] => 45
                    [clicks] =>69
                    [unique_clicks] => 123
                )

            [last_7_days] => Array
                (
                    [sent] => 25
                    [hard_bounces] =>125
                    [soft_bounces] => 29
                    [rejects] => 42
                    [complaints] => 42
                    [unsubs] => 42
                    [opens] => 42
                    [unique_opens] => 42
                    [clicks] => 42
                    [unique_clicks] => 42
                )

            [last_30_days] => Array
                (
                    [sent] => 42
                    [hard_bounces] => 42
                    [soft_bounces] => 42
                    [rejects] => 42
                    [complaints] => 42
                    [unsubs] => 42
                    [opens] => 42
                    [unique_opens] => 42
                    [clicks] => 42
                    [unique_clicks] => 42
                )

            [last_60_days] => Array
                (
                    [sent] => 42
                    [hard_bounces] => 42
                    [soft_bounces] => 42
                    [rejects] => 42
                    [complaints] => 42
                    [unsubs] => 42
                    [opens] => 42
                    [unique_opens] => 42
                    [clicks] => 42
                    [unique_clicks] => 42
                )

            [last_90_days] => Array
                (
                    [sent] => 42
                    [hard_bounces] => 42
                    [soft_bounces] => 42
                    [rejects] => 42
                    [complaints] => 42
                    [unsubs] => 42
                    [opens] => 42
                    [unique_opens] => 42
                    [clicks] => 42
                    [unique_clicks] => 42
                )

            [all_time] => Array
                (
                    [sent] => 42
                    [hard_bounces] => 42
                    [soft_bounces] => 42
                    [rejects] => 42
                    [complaints] => 42
                    [unsubs] => 42
                    [opens] => 42
                    [unique_opens] => 42
                    [clicks] => 42
                    [unique_clicks] => 42
                )

        )

)

How can I extract every value as a single line?

Example :

  • $today-sent="43"
  • $7days-sent="25"
  • $today-hard_bounces="64"

回答1:


$todaySent = $array['stats']['today']['sent'];
$lastSeven = $array['stats']['last_7_days']['sent'];
$todayBounce = $array['stats']['today']['hard_bounces'];

You can do whatever you want with the variables storing the values.



来源:https://stackoverflow.com/questions/27027716/extract-values-from-array-php-or-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!