How to add an array with itself more data?

Asked

Viewed 60 times

0

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

     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')
                                ),
                            ),
                        ));
                    }
                }

1 answer

2


You cannot "add" arrays this way. To merge two or more arrays you must use the function array_merge.

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')
            ),
        ),
)));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.