【问题标题】:how to Array inside Array Data in laravel如何在laravel中的数组数据中排列
【发布时间】:2020-03-18 05:43:00
【问题描述】:

我正在尝试在 BLADE 文件中获取数组值。我的数组如下所示,但我无法在数组中获取值。

我有 [student_levels]=> [level] 数据

laravel 代码

foreach($items as $item)
{
    echo $item['student_levels']['level'];
}

$items 是数组

Array
(
    [0] => Array
        (
            [_id] => 5c1e4295b0dace71ec62e325
            [email] => dhavalpansuriya1195@gmail.com
            [franchisecode] => MELHH
            [title] => Mr
            [firstname] => dhaval s
            [lastname] => patel
            [gender] => Male
            [age] => 16-18
            [phone] => 9601354880
            [address] => rajkot
            [city] => Ahmedabad
            [country] => India
            [tempcode] => hUmoEF
            [studentid] => HTNKLF
            [updated_at] => 2019-11-21 13:32:31
            [created_at] => 2018-12-22 19:26:37
            [student_status] => eda
            [student_levels] => Array
                (
                    [_id] => 5c8b11d2b0dace2f9a044d86
                    [student_id] => HTNKLF
                    [teacher_id] => 5c1e1ab5b0dace716e429654
                    [level_name] => recomended_level
                    [level] => Level 1
                    [comments] => hhbhhhh
                    [exam_type] => eda
                    [student_course] => 
                    [updated_at] => 2019-03-15 08:15:38
                    [created_at] => 2019-03-15 08:15:38
                )

        )

【问题讨论】:

    标签: php arrays laravel mongodb


    【解决方案1】:

    你有一个数组里面有一个数组..所以你可以使用foreach循环

     @foreach($items as $item)
       {{$item['student_levels']['level']}}
     @endforeach
    

    或者直接

    {{$items[0]['student_levels']['level']}}
    

    【讨论】:

    • 请在您的代码中添加一些解释,以便其他人可以从中学习
    【解决方案2】:

    您的数组似乎返回了一组学生,您的数组中有一个额外的级别。因此,要获取第一个学生级别,您需要使用以下代码:

    echo $item[0]['student_levels']['level'];
    

    也许获取此数据的代码可以优化为仅获取一个学生,您可以发布此代码吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-20
      相关资源
      最近更新 更多