July 10th, 2013, 01:43 PM
Help w/ Dividing Array into Columns
I'm using the following PHP script on an e-commerce site to display retail locations out of a database:
The issue is that I now need to display the locations in four columns displaying from top to bottom in each one in ABC order. But not every state has a location. So the way it's divided up needs to be based on the number of results in the $states array.
$state_ids = array_map('break_down_by_id', Db_DbHelper::queryArray('select distinct state_id as id from foxylocator_locations where country_id = ?', array($country->id)));
$states = Shop_CountryState::create()->where('id in (?)', array($state_ids))->find_all();
<? foreach($states as $state): ?>
<h5><?= $state->name ?></h5>
<? endforeach ?>
How can I take the array and divide it up into four equal (or close to it) <div> columns?
Thank you for your help!
July 10th, 2013, 02:09 PM
Actually, if I'm reading this right, every state you display does have a location. Because you're getting the list of states from the locations.
If the question is as simple as "I have an array that I need to split into four mostly equal parts" then array_chunk.