Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #17 from Borales/array-enh
Browse files Browse the repository at this point in the history
Adding ability to find required value from CAttributeCollection
  • Loading branch information
Antonio Ramirez committed Mar 5, 2014
2 parents de9cb19 + 802dbbf commit 69fdab1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Helpers/ArrayX.php
Expand Up @@ -30,7 +30,7 @@ class ArrayX
* $name = ArrayX::get($array, 'user.name', 'Taylor');
* </code>
*
* @param array $array
* @param array|\CAttributeCollection $array
* @param string $key
* @param mixed $default
* @return mixed
Expand All @@ -39,6 +39,10 @@ public static function get($array, $key, $default = null)
{
if (is_null($key)) return $array;

// In case if given array is instance of CAttributeCollection.
// For example, Yii::app()->params value
if($array instanceof \CAttributeCollection) $array = $array->toArray();

// To retrieve the array item using dot syntax, we'll iterate through
// each segment in the key and look for that value. If it exists, we
// will return it, otherwise we will set the depth of the array and
Expand Down

0 comments on commit 69fdab1

Please sign in to comment.