How to add an array with itself more data?

0

It's the following galera. I have a for and inside it I have an array ($ smses) that receives ($ smses = $ smses + 'the data from my application'). The problem is that this does not work, I would like to know how I add the new data from the new index.

     if ($campanha['Smse']['entity'] == 0) {
                for ($i=0; $i < $tamanho; $i++) { 

                    $smses =  $smses + $this->Phone->find('list', array(                      
                        'fields' => array('Phone.phone'),
                        'conditions' => array(
                            $conditions,
                            'Phone.type' => 2,
                            'Phone.phone !=' => '',
                            ),
                        'joins' => array(
                            array(
                                'table' => 'contacts',
                                'alias' => 'Contact',
                                'type' => 'LEFT',
                                'conditions' => array('Phone.contact_id = Contact.id')
                                ),        
                            array(
                                'table' => 'prospects',
                                'alias' => 'Prospect',
                                'type' => 'LEFT',
                                'conditions' => array('Prospect.contact_id = Contact.id')
                                ),
                            ),
                        ));
                    }
                }
    
asked by anonymous 02.02.2015 / 21:09

1 answer

2

You can not "add" arrays that way. To merge two or more arrays you must use the array_merge function.

In your case it would look something like this:

$smses =  array_merge($smses, $this->Phone->find('list', array(                      
    'fields' => array('Phone.phone'),
    'conditions' => array(
        $conditions,
        'Phone.type' => 2,
        'Phone.phone !=' => '',
        ),
    'joins' => array(
        array(
            'table' => 'contacts',
            'alias' => 'Contact',
            'type' => 'LEFT',
            'conditions' => array('Phone.contact_id = Contact.id')
            ),        
        array(
            'table' => 'prospects',
            'alias' => 'Prospect',
            'type' => 'LEFT',
            'conditions' => array('Prospect.contact_id = Contact.id')
            ),
        ),
)));
    
02.02.2015 / 21:21