简体   繁体   English

如何使用 Laravel 解析嵌套数组

[英]How to parse nested Array with Laravel

Hey guys i am new of the laravel, how can i parse this output array?嘿伙计们,我是 laravel 的新手,我该如何解析这个 output 数组? This is my array is coming from repeater using jquery.这是我的阵列来自使用 jquery 的中继器。

    Array
(
    [tour_baslik] => 1. Day
    [tour_icerik] => content here....
    [lunch] => Array
        (
            [0] => 2
        )

    [dinner] => Array
        (
            [0] => 1
            [1] => 2
        )

)
Array
(
    [tour_baslik] => 2.Day
    [tour_icerik] => content 2 here...
    [lunch] => Array
        (
            [0] => 1
            [1] => 2
        )

    [dinner] => Array
        (
            [0] => 2
        )

)

I need parse like that but i'm stuck:我需要这样解析,但我被卡住了:

foreach($myarray as $key => $data){
echo $key . '-' . $data; }

Output must be: Output 必须是:

tour_baslik - 1.day
tour_icerik - content here..
lunch - 2
dinner - 1,2

If you need to iterate through all items of your input, you could use a recursive function like the following:如果您需要遍历输入的所有项目,您可以使用递归 function,如下所示:

function iterator($key, $value) {
    if (is_array($value)) {
        foreach ($value as $key => $value) {
            iterator($key, $value);
        }
    } else {
        echo !empty($key) ? "$key - " : "";
        echo $value."\n";
    }
}

iterator(null, $input);

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

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