duanjue6575 2018-06-01 20:01
浏览 30

foreach数组使用刀片

I started using Blade template engine with codeigniter, and Google Api i use blade to develope an old project created by another developers for this reason i have to keep the same blade data structure.

this is the Blade code written by a different developpers (i need to keep it ):

@foreach ($analytics['countries'] as $country)
                            ['{{$country['country']}}',    {{$country['visits_percent']}}],
                    @endforeach

this is my PHP code

$this->blade->view()->make('analytics/analytics', ['analytics' => $analytics]);

and this is my $analtics array :

 Array
(
    [0] => Array
        (
            [0] => Canada
            [1] => 3367
        )

    [1] => Array
        (
            [0] => United States
            [1] => 202
        )

    [2] => Array
        (
            [0] => Malaysia
            [1] => 34
        )

    [3] => Array
        (
            [0] => Mexico
            [1] => 31
        )

    [4] => Array
        (
            [0] => Peru
            [1] => 23
        )

    [5] => Array
        (
            [0] => Brazil
            [1] => 21
        )

    [6] => Array
        (
            [0] => United Kingdom
            [1] => 21
        )

    [7] => Array
        (
            [0] => Netherlands
            [1] => 17
        )

    [8] => Array
        (
            [0] => Nepal
            [1] => 14
        )

    [9] => Array
        (
            [0] => India
            [1] => 12
        )

    [10] => Array
        (
            [0] => Belarus
            [1] => 11
        )

    [11] => Array
        (
            [0] => France
            [1] => 9
        )

    [12] => Array
        (
            [0] => Ireland
            [1] => 9
        )

    [13] => Array
        (
            [0] => Germany
            [1] => 7
        )

    [14] => Array
        (
            [0] => Philippines
            [1] => 6
        )

    [15] => Array
        (
            [0] => Singapore
            [1] => 5
        )

    [16] => Array
        (
            [0] => Bangladesh
            [1] => 4
        )

    [17] => Array
        (
            [0] => Italy
            [1] => 4
        )

    [18] => Array
        (
            [0] => Serbia
            [1] => 4
        )

    [19] => Array
        (
            [0] => Australia
            [1] => 3
        )

    [20] => Array
        (
            [0] => Belgium
            [1] => 3
        )

    [21] => Array
        (
            [0] => Indonesia
            [1] => 3
        )

    [22] => Array
        (
            [0] => Iran
            [1] => 3
        )

    [23] => Array
        (
            [0] => Jordan
            [1] => 3
        )

    [24] => Array
        (
            [0] => Morocco
            [1] => 3
        )

    [25] => Array
        (
            [0] => China
            [1] => 2
        )

    [26] => Array
        (
            [0] => Colombia
            [1] => 2
        )

    [27] => Array
        (
            [0] => Moldova
            [1] => 2
        )

    [28] => Array
        (
            [0] => Pakistan
            [1] => 2
        )

    [29] => Array
        (
            [0] => Poland
            [1] => 2
        )

    [30] => Array
        (
            [0] => Romania
            [1] => 2
        )

    [31] => Array
        (
            [0] => South Africa
            [1] => 2
        )

    [32] => Array
        (
            [0] => Thailand
            [1] => 2
        )

    [33] => Array
        (
            [0] => Turkey
            [1] => 2
        )

    [34] => Array
        (
            [0] => Argentina
            [1] => 1
        )

    [35] => Array
        (
            [0] => El Salvador
            [1] => 1
        )

    [36] => Array
        (
            [0] => Hong Kong
            [1] => 1
        )

    [37] => Array
        (
            [0] => Japan
            [1] => 1
        )

    [38] => Array
        (
            [0] => Kenya
            [1] => 1
        )

    [39] => Array
        (
            [0] => Latvia
            [1] => 1
        )

    [40] => Array
        (
            [0] => New Zealand
            [1] => 1
        )

    [41] => Array
        (
            [0] => Russia
            [1] => 1
        )

    [42] => Array
        (
            [0] => Saudi Arabia
            [1] => 1
        )

    [43] => Array
        (
            [0] => South Korea
            [1] => 1
        )

)

my question is how can i produce the same array structure for blade thank you

  • 写回答

1条回答 默认 最新

  • douhan1860 2018-06-01 20:44
    关注

    I hope this code useful for you :

    Route::get('/test', function (Request $request) {
    $analytics=[
        [
            'Canada',
            3367
        ],
        [
            'United States',
            202
        ],
        [
            'Malaysia',
            34
        ],
    ];
    
    return view('welcome',compact('analytics'));
    })
    

    and you can use this code in view :

    @foreach( $analytics as  $analytic)
        <p>
            country = {{$analytic[0]}}
            <br>
            code = {{$analytic[1]}}
            <tr>
        </p>
    @endforeach
    
    评论

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致