繁体   English   中英

Laravel中的多维数组

[英]multidimensional array in laravel

我可以使用$post->user->name循环显示用户数据(第二个数组) ,但是如何显示第三个数组数据? 它不能作为$post->likes->user_id
请帮忙。
这是我的数组列表:

    [{
    "id": 13,
    "user_id": 1,
    "content": "\"The reason most people never reach their goals is that they don't define them, or ever seriously consider them as believable or achievable. Winners can tell you where they are going, what they plan to do along the way, and who will be sharing the adventure with them.\" --Denis Waitley",
    "status": 0,
    "created_at": "2017-07-06 04:02:41",
    "updated_at": "2017-07-06 04:02:41",
    "user": {
        "id": 1,
        "name": "hardeep singh",
        "gender": "male",
        "slug": "hardeep-singh",
        "email": "hardeepphp@yahoo.com",
        "pic": "47224964-profile-pictures.jpg",
        "role": "admin",
        "created_at": "2017-02-21 06:06:28",
        "updated_at": "2017-02-21 06:06:28"
    },
    "likes": {
        "id": 2,
        "posts_id": 13,
        "user_id": 3,
        "created_at": "2017-07-07 17:52:18"
    }
}, {
    "id": 12,
    "user_id": 10,
    "content": "\"People who succeed have momentum. The more they succeed, the more they want to succeed, and the more they find a way to succeed. Similarly, when someone is failing, the tendency is to get on a downward spiral that can even become a self-fulfilling prophecy.\" --Tony Robbins",
    "status": 0,
    "created_at": "2017-07-06 04:00:14",
    "updated_at": "2017-07-06 04:00:14",
    "user": {
        "id": 10,
        "name": "Ogran Gysn",
        "gender": "male",
        "slug": "ogran-gysn",
        "email": "ogran@gmail.com",
        "pic": "ee.jpg",
        "role": "company",
        "created_at": "2017-03-10 10:48:19",
        "updated_at": "2017-03-10 10:48:19"
    },
    "likes": {
        "id": 3,
        "posts_id": 12,
        "user_id": 3,
        "created_at": "2017-07-07 17:52:33"
    }
}, {
    "id": 11,
    "user_id": 9,
    "content": "\"Thinking should become your capital asset, no matter whatever ups and downs you come across in your life.\" --A.P.J. Abdul Kalam",
    "status": 0,
    "created_at": "2017-07-06 03:59:47",
    "updated_at": "2017-07-06 03:59:47",
    "user": {
        "id": 9,
        "name": "john lewis",
        "gender": "male",
        "slug": "john-lewis",
        "email": "john@gmai.com",
        "pic": "scs.png",
        "role": "company",
        "created_at": "2017-03-10 04:04:27",
        "updated_at": "2017-03-10 04:04:27"
    },
    "likes": {
        "id": 17,
        "posts_id": 11,
        "user_id": 1,
        "created_at": "2017-07-13 10:07:56"
    }
}, {
    "id": 10,
    "user_id": 3,
    "content": "Happiness is a butterfly, which when pursued, is always beyond your grasp, but which, if you will sit down quietly, may alight upon you",
    "status": 0,
    "created_at": "2017-07-06 03:59:19",
    "updated_at": "2017-07-06 03:59:19",
    "user": {
        "id": 3,
        "name": "anita donal",
        "gender": "female",
        "slug": "anita-donal",
        "email": "anita@yahoo.com",
        "pic": "47354305-profile-pictures.jpg",
        "role": null,
        "created_at": "2017-02-21 06:07:39",
        "updated_at": "2017-02-21 06:07:39"
    },
    "likes": {
        "id": 13,
        "posts_id": 10,
        "user_id": 1,
        "created_at": "2017-07-13 10:01:43"
    }
}, {
    "id": 9,
    "user_id": 1,
    "content": "Take up one idea. Make that one idea your life--think of it, dream of it, live on that idea. Let the brain, muscles, nerves, every part of your body, be full of that idea, and just leave every other idea alone.",
    "status": 0,
    "created_at": "2017-07-06 03:58:40",
    "updated_at": "2017-07-06 03:58:40",
    "user": {
        "id": 1,
        "name": "hardeep singh",
        "gender": "male",
        "slug": "hardeep-singh",
        "email": "hardeepphp@yahoo.com",
        "pic": "47224964-profile-pictures.jpg",
        "role": "admin",
        "created_at": "2017-02-21 06:06:28",
        "updated_at": "2017-02-21 06:06:28"
    },
    "likes": {
        "id": 19,
        "posts_id": 9,
        "user_id": 1,
        "created_at": "2017-07-13 10:08:51"
    }
}, {
    "id": 3,
    "user_id": 9,
    "content": "have a nic day :)",
    "status": 0,
    "created_at": "2017-07-05 07:59:22",
    "updated_at": "2017-05-09 08:56:59",
    "user": {
        "id": 9,
        "name": "john lewis",
        "gender": "male",
        "slug": "john-lewis",
        "email": "john@gmai.com",
        "pic": "scs.png",
        "role": "company",
        "created_at": "2017-03-10 04:04:27",
        "updated_at": "2017-03-10 04:04:27"
    },
    "likes": {
        "id": 1,
        "posts_id": 3,
        "user_id": 1,
        "created_at": "2017-07-13 10:33:43"
    }
}, {
    "id": 1,
    "user_id": 3,
    "content": "This is demo post",
    "status": 0,
    "created_at": "2017-07-04 18:25:14",
    "updated_at": "-0001-11-30 00:00:00",
    "user": {
        "id": 3,
        "name": "anita donal",
        "gender": "female",
        "slug": "anita-donal",
        "email": "anita@yahoo.com",
        "pic": "47354305-profile-pictures.jpg",
        "role": null,
        "created_at": "2017-02-21 06:07:39",
        "updated_at": "2017-02-21 06:07:39"
    },
    "likes": null
}, {
    "id": 2,
    "user_id": 3,
    "content": "this is post by me, i am anita donal",
    "status": 0,
    "created_at": "2017-03-23 16:14:50",
    "updated_at": "-0001-11-30 00:00:00",
    "user": {
        "id": 3,
        "name": "anita donal",
        "gender": "female",
        "slug": "anita-donal",
        "email": "anita@yahoo.com",
        "pic": "47354305-profile-pictures.jpg",
        "role": null,
        "created_at": "2017-02-21 06:07:39",
        "updated_at": "2017-02-21 06:07:39"
    },
    "likes": {
        "id": 21,
        "posts_id": 2,
        "user_id": 1,
        "created_at": "2017-07-13 10:36:30"
    }
}]

在数组中,您不能使用->我假设您的数组在$ post对象中。

$post->likes->user_id.
  foreach($post as $row){
           $row['like']['user_id']
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM