#4709: Set::combine returns array_combine warning when encountering an empty 
array
---------------------------------------------------------+------------------
    Reporter:  Laeffe                                    |         Owner:  
the_undefined
        Type:  Test Case                                 |        Status:  
reopened     
    Priority:  Medium                                    |     Milestone:  
1.2.x.x      
   Component:  Core Libs                                 |       Version:  1.2 
Final    
    Severity:  Normal                                    |    Resolution:       
        
    Keywords:  set combine warning array_combine Laeffe  |   Php_version:  n/a  
        
Cake_version:  1.2.0.6311                                |  
---------------------------------------------------------+------------------
Comment (by techlands):

 {{{
 <?php

 // MainModel hasMany SubModel

 $test['MainModel'] = array
 (
     0 => array
         (
             'id' => 1,
             'SubModel' => array
                 (
                     0 => array
                         (
                             'id' => 4
                         )
                 )
         ),
     //Query may product no SubModel records like below
     1 => array
         (
             'id' => 2,
             'SubModel' => array()
         ),
     2 => array
         (
             'id' => 3,
             'SubModel' => array
                 (
                     0 => array
                         (
                             'id' => 6
                         )
                 )
         )
 );


 $combineResult = Set::combine($test['MainModel'], '/id', '/SubModel/id');
 //returns array_combine warning because the found values are less then the
 found keys


 //how i got around this



 $foundKeys = Set::extract('/id', $test['MainModel']);
 $foundValues = Set::extract('/SubModel/id', $test['MainModel']);

 if (count($foundKeys) == count($foundValues))
 {
         $combineResult = array_combine($foundKeys, $foundValues);
 }

 ?>

 }}}

-- 
Ticket URL: <https://trac.cakephp.org/ticket/4709#comment:9>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design 
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. 
Our primary goal is to provide a structured framework that enables PHP users at 
all levels to rapidly develop robust web applications, without any loss to 
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"tickets cakephp" 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/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to