Hi Zicky,
I think I may have a solution for you. In /lib/common.php we have the following function:
// array_groupBy:
// eg. $recordsByNum = array_groupBy($records, 'num');
// eg. $recordsByCategory = array_groupBy($records, 'category', true);
// foreach ($recordsByCategory as $category => $categoryRecords) { ;;; }
// PHP Alternate: $recordsByNum = array_combine(array_column($menuRecords, 'num'), $menuRecords);
function array_groupBy($recordList, $indexField, $resultsAsArray = false) {
It allows you to group the returned results into an associative array with the column of your choice. In your case you may use it like:
$groupedStaffRecords = array_groupBy($staffRecords, 'categories', true);
Putting that line beneath your $staffRecords list near the top of the file. You would then loop through the $groupedStaffRecords using a foreach loop:
<?php foreach ($groupedStaffRecords as $category => $records) :?>
<?php if($category == '4'): ?>
<?php $total_staff = count($records); // Set a total variable to use for the columns?>
<?php foreach ($records as $key => $record): // this is the loop of the individual records in this category ?>
<!--below it checks if it's the last result and is even (% 2) modulus operator checks if it is divisible by the number -->
<?php if ($key == $total_staff && $total_staff % 2 !== 0) : ?>
<div class="small-12 medium-12 large-12 cell">
<?php else: ?>
<div class="small-6 medium-6 large-6 cell">
<?php endif ?>
<!-- show record content -->
</div>
<?php endforeach ?>
<?php endif ?>
<?php endforeach ?>
You'll probably have to modify some things to ensure they work for your specific use case, but this should help to get you started in the right direction.
Let me know if this helps or if I need to clarify anything.
Jenna Cooke - PHP Programmer
interactivetools.com