Skip to content

Instantly share code, notes, and snippets.

@athlan
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save athlan/73d6084d643241ae7d84 to your computer and use it in GitHub Desktop.
Save athlan/73d6084d643241ae7d84 to your computer and use it in GitHub Desktop.
<?php
public function listingResultFixedPostions(&$aResult) {
$fixedPositionsBuckets = array();
$count = count($aResult);
foreach($aResult as $key => &$row) {
if(isset($row['news_date_order_fixedposition'])) {
$pos = $row['news_date_order_fixedposition'];
if($pos >= 1 && $pos <= $count) // check if requested position os out the bound
{
if(!is_array($fixedPositionsBuckets[$pos]))
$fixedPositionsBuckets[$pos] = array();
$fixedPositionsBuckets[$pos][] = $row;
unset($aResult[$key]);
}
}
}
unset($row); // loose reference from last item of foreach
$aResultStack = array();
$pos = 0;
foreach($aResult as &$row) {
++$pos;
if($fixedPositionsBuckets[$pos]) {
foreach($fixedPositionsBuckets[$pos] as &$rowPos)
$aResultStack[] = $rowPos;
unset($rowPos);
}
$aResultStack[] = $row;
}
unset($row); // loose reference from last item of foreach
$aResult = $aResultStack;
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment