Created
February 16, 2016 13:16
-
-
Save nielsnuebel/d4efeb474d9d346067bb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * 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