Skip to content

Instantly share code, notes, and snippets.

@philsturgeon
Created May 27, 2010 20:21
Show Gist options
  • Save philsturgeon/416292 to your computer and use it in GitHub Desktop.
Save philsturgeon/416292 to your computer and use it in GitHub Desktop.
/**
* 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;
}
@yorickpeterse
Copy link

@param  mixed

Very descriptive :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment