Home Forums Add-ons Repeater Field Repeater + Show lowest rate by term Reply To: Repeater + Show lowest rate by term


    Using the repeater to store mortgage rates, some with the same term.

    What the PHP dose:

    At some point, the code sorts ALL rows/array by mortgage term (1,2,3,4,5,10 years).

    Then if the arrays have more then 1 x term (example 10 x 5-year), it finds the term with the lowest rate and only displays that rate/term/type.

    This isn’t just an issue with 5-year rates, we could have 5000 x 1-year rates and 40 x 3-year rates and the sort/filter will always show the lowest rate for each term.

    This part of the code has always worked fine, that’s why it has been so hard to troubleshoot.

    	$arr = get_field('acf_rates_fixed');
    	$new_arr = array(); // not sure what this dose
    	foreach($arr as $val){
    		$val['acf_rates_rate'];// not sure what this dose
    			$cur_rate = $new_arr[$val['acf_rates_term']]['acf_rates_rate'];
    			$new_arr[$val['acf_rates_term']]['acf_rates_rate'] = ($cur_rate > /* > is low and < is high */ $val['acf_rates_rate']) ? $val['acf_rates_rate'] : $cur_rate;
    		} else {
    			$new_arr[$val['acf_rates_term']] =  $val;
    	ksort($new_arr); // not sure what this dose
    	$result = array_values($new_arr); // not sure what this dose
    		foreach($new_arr as $result) { ?>
        <!-- these 3 values show perfectly -->
        acf_rates_rate = <?php echo $result['acf_rates_rate']?> <br />
        acf_rates_type = <?php echo $result['acf_rates_type']?> <br />
        acf_rates_term = <?php echo $result['acf_rates_term']?> <br />
        <!-- these show from another row --->
        acf_rates_comments = <?php echo $result['acf_rates_comments']?> <br />
        acf_rates_restrictions = <?php echo $result['acf_rates_restrictions']?> <br />
        acf_rates_occupancy = <?php echo $result['acf_rates_occupancy']?> <br />
        acf_rates_amortization = <?php echo $result['acf_rates_amortization']?> <br />
    <?php	} ?>

    What the issue is:

    Anytime it detects a duplicate term and finds the lowest rate, any keys after “rate/term/type” are from an entirely different rate, but keys from a similar term.

    Any suggestions?