I do a print_r($my_var)
and get a result like:
Array ( [0] => Array ( [email] => [email protected] ) [1] => Array ( [email] => [email protected] ) )
How to get a new array like
$mails= array( '[email protected]','[email protected]' );
I do a print_r($my_var)
and get a result like:
Array ( [0] => Array ( [email] => [email protected] ) [1] => Array ( [email] => [email protected] ) )
How to get a new array like
$mails= array( '[email protected]','[email protected]' );
$mails = array_map(function ($x){
return $x['email'];
}, $my_var);
Update
Using a foreach loop instead of array_map:
$mails = array();
foreach($my_var as $emailArr){
$mails[] = $emailArr['email'];
}
array_values($my_var[0])
just returns an array containing the first email address, not all of them.
array_values($myvar[0]);
// Will return the values inside you array ( I noticed your array was nested, so I did the values of he 0 element).
http://www.php.net/manual/en/function.array-values.php
Highly recommend just having a little read of all the available array functions just quickly so you can see what is possible.
foreach ($myvar->result() as $val) $to .= $val->email . ", ";
but to get rid ot that last comma?rtrim($to, ', ')