Skip to content

Instantly share code, notes, and snippets.

@nielsnuebel
Created February 16, 2016 13:16
Show Gist options
  • Select an option

  • Save nielsnuebel/d4efeb474d9d346067bb to your computer and use it in GitHub Desktop.

Select an option

Save nielsnuebel/d4efeb474d9d346067bb to your computer and use it in GitHub Desktop.
/**
* Get the Repeatable Field information.
*
* @param string $repeatableField The component option.
* @param boolean $returnarray The component option.
*
* @return object An object with the information for the component.
*
* @since 1.5
*/
public static function getRepeatable($repeatableField, $returnarray = true)
{
$firstkey = false;
$id = array();
$repeatableField = json_decode($repeatableField);
if (is_null($repeatableField))
{
return $repeatableField;
}
if (!$returnarray)
{
$result = new stdClass;
}
else
{
$result = array();
}
foreach ($repeatableField as $key => $values)
{
$i = 0;
if (!$returnarray)
{
if (!$firstkey)
{
$count = 0;
foreach ($values as $value)
{
$id[$count] = $value;
$count++;
}
$firstkey = true;
}
foreach ($values as $value)
{
if (!isset($result->$id[$i]))
{
$result->$id[$i] = new stdClass;
}
$result->$id[$i]->$key = $value;
$i++;
}
}
else
{
foreach ($values as $value)
{
if (!isset($result[$i]))
{
$result[$i] = new stdClass;
}
$result[$i]->$key = $value;
$i++;
}
}
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment