1

I want to get array from this json file like $event['days'], $event['name'] and etc but i need to say all path like $event[0]['event_timers'][0]['date'] and i cant get all arrays, becouse need to change '0' to 1,2,3 and etc.. this is my .json file

{
"events": {
    "active": "1",
    "event_timers": {
        "1": {
            "name": "xWeb Download",
            "days": {
                "1": "12:00,13:00"
            }
        },
        "2": {
            "name": "xWeb Download",
            "days": {
                "1": "12:00,13:00",
                "3": "11:30,12:30"
            }
        },
        "3": {
            "name": "xWeb Download",
            "days": {
                "1": "12:00,13:00",
                "3": "11:30,12:30"
            }
        },
        "4": {
            "name": "ASads",
            "days": {
                "6": "12:30"
            }
        }
    }
}

} and this is from controller

 public function event()
{

    $events = json_decode(file_get_contents(storage_path() . "/event_config.json"), true);


    $days = [1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 7 => 'Sunday',];
    $ii = 0;
    $iii = 1;
    $timers = [];
    foreach($events as $event){
        $name = $event['name'];
        $day = $event['days'];
    }
    dd($event['days']);
    return view('ap.event');
}
  • 1
    `$events` has a single `events`, which has two properties: `active`, and `event_timers`. `event_timers` is the array that you're trying to get data from, and that you need to iterate over. So your foreach needs to iterate over `$events['events']['event_timers']` – aynber Aug 08 '22 at 11:45

0 Answers0