Last active
August 29, 2015 14:03
-
-
Save athlan/73d6084d643241ae7d84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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