Created
May 27, 2010 20:21
-
-
Save philsturgeon/416292 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
/** | |
* Force Array | |
* | |
* Take a totally mixed item and parse it into an array compatible with EE's Template library | |
* | |
* @access private | |
* @param mixed | |
* @return string | |
*/ | |
private function _force_array($var, $level = 1) | |
{ | |
if (is_object($var)) | |
{ | |
$var = (array) $var; | |
} | |
if($level == 1 && !isset($var[0])) | |
{ | |
$var = array($var); | |
} | |
if (is_array($var)) | |
{ | |
// Make sure everything else is array or single value | |
foreach($var as $index => &$child) | |
{ | |
$child = self::_force_array($child, $level + 1); | |
if (is_object($child)) | |
{ | |
$child = (array) $child; | |
} | |
// Format for EE syntax looping | |
if (is_array($child) AND ! is_int($index)) | |
{ | |
$child = array($child); | |
} | |
} | |
} | |
return $var; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very descriptive :)