Hi all,
I needed a function to return more than one value for a key so this is
what I have done. I hope it will helps someone.

 /**
       * Generates an array with keys defined by $keyPath and
concatenated values from $valuePath
           *
           * @param array $conditions limites the array of result if defined
           * @param mixed $keyPath A dot-separated
           * @param mixed $valuePath A dot-separated string.
           * @param mixed $delimeter string to seperate values.
           * @param numerical $recursive defines depth of search.
           * @return array Array with keys defined from  $keyPath and values
concatenated string of $valuePath
           * @access public
           */
        function generateListExtended($conditions = null, $keyPath,
$valuePath = null, $delimeter = " ", $recursive = -1)
        {
                if(empty($valuePath))
                        return false;

                $this->recursive = $recursive;
                $rows = $this->findAll($conditions);
                if(empty($rows))
                        return null;
                $returnKeys = Set::extract($rows, $keyPath);

                $listVals = array();
                foreach($valuePath as $key => $value)
                        $listVals[] = Set::extract($rows, $value);

                $returnVals = array();
                foreach($listVals as $fieldKey => $fieldValue)
                {
                        foreach($fieldValue as $key => $value)
                        {
                                if(!empty($value))
                                {
                                        if(isset($returnVals[$key]))
                                                $returnVals[$key] .= 
$delimeter.$value;
                                        else
                                                $returnVals[$key]  = $value;
                                }
                        }
                }

                if (!empty($returnKeys) && !empty($returnVals)) {
             $return = array_combine($returnKeys, $returnVals);
             return $return;
        }
        return null;
        }


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to