Foreach loop through Gravity Forms entries

Not sure how relevant the answer is now, but it might help someone in future.

  1. It would be advisable to switch $entries and $entry. It’s quite confusing that you use $entries for singular entry and $entry for an array of entries.

  2. Define what output you are looking for. You are looking to get an array, but you’re rewriting your values with each loop – that’s why the last one stands- like you’re repainting a house and wondering why only the top color can be seen…

  3. I’d say you want to do this to the $calendar_data array and an $outputx output:

    $calendar_data = array();
    
    $outputx = "";
    
    $entries = GFAPI::get_entries($form_id, $search_criteria, $sorting, $paging, $total_count);
    
    foreach ($entries as $entry) {
        $idx = rgar($entry, 'id');
        $calendar_data[$idx]["fname"] = rgar($entry, '13.3');
        $calendar_data[$idx]["lname"] = rgar($entry, '13.6');
        $calendar_data[$idx]["pto_start"] = rgar($entry, '1');
        $calendar_data[$idx]["pto_end"] = rgar($entry, '3');
        $calendar_data[$idx]["e_location"] = rgar($entry, '16');
        $calendar_data[$idx]["pto_approval"] = rgar($entry, '15');
    
        $supervisor_location = um_user('employee_location');
    
        if (($supervisor_location === 'Elk City, OK') && ($e_location === 'Elk City, OK' )) {
            if ($pto_start != $this->currentDate) {
                $outputx .= '<div id="' . $this->currentDate . '" class="day ' . ($cellNumber % 7 == 1 ? ' start ' : ($cellNumber % 7 == 0 ? ' end ' : ' ')) .
                ($cellContent == null ? 'mask' : '') . '">' . $cellContent . '</div>';
            } elseif ($pto_start == $this->currentDate) {
                $outputx .= '<div id="' . $this->currentDate . '" class="day has-pto ' . ($cellNumber % 7 == 1 ? ' start ' : ($cellNumber % 7 == 0 ? ' end ' : ' ')) .
                ($cellContent == null ? 'mask' : '') . '">' . $cellContent . '<div class="inner-pto-cal ' . lcfirst($pto_approval) . '">' . $fname . ' ' . $lname . '</div></div>';
            }
        }
    }