我想要这个数组输出,因为我需要PHP中的Google_service_calendar_event的与会者:
Array (
[0] => Array ( [email] => myemail@gmail.com )
[1] => Array ( [email] => myemail1@gmail.com )
[2] => Array ( [email] => myemail2@gmail.com )
[3] => Array ( [email] => myemail3@yahoo.com ) )
这是我的代码PHP:
$invitados_inicial = array(array('email' => $correo_del_director));
foreach ($_SESSION['gcal_correo_aplicantes'] as $correo_aplica) {
$invitados_inicial['email'] = $correo_aplica;
}
这就是我得到的(不是我需要的):
Array (
[0] => Array ( [email] => myemail@gmail.com )
[email] => Array (
[0] => myemail1@gmail.com
[1] => myemail2@gmail.com
[2] => myemail3@yahoo.com
)
)
无论如何,我没有得到我想要的输出数据,我的参加者无法进入Google_service_calendar_event。如何获取我的数据输出?
答案 0 :(得分:1)
您必须澄清$_SESSION['gcal_correo_aplicantes']
的结构才能得到正确的答案。在下面,我假设它是这样的:
$session = array( "email1@add.com","email2@add.com");
第一个解决方案:
<?php
$invitados_inicial=[];
for ($i=0; $i<count($session);$i++) {
$invitados_inicial[$i] = array( 'email' => $session[$i] );
}
var_dump($invitados_inicial);
第二个选项:
<?php
$invitados_inicial=[];
foreach ($session as $correo_aplica) {
$invitados_inicial[] = array( 'email' => $session[$i] );
}
var_dump($invitados_inicial);
答案 1 :(得分:0)
试试这个:
$invitados_inicial = array(array('email' => $correo_del_director));
foreach ($_SESSION['gcal_correo_aplicantes'] as $correo_aplica) {
foreach ($correo_aplica as $value) {
$arr['email'] = $value;
$invitados_inicial[] = $arr;
}
}
答案 2 :(得分:0)
感谢您的帮助,您给了我一些想法,我可以解决这个问题:
$invitados_inicial = array(array('email' => $correo_del_director));
// Agrego a los candidatos seleccionados a listado de participantes
foreach ($_SESSION['gcal_correo_aplicantes'][0] as $correo_aplica) {
$invitados_inicial[] = array('email' => $correo_aplica);
}
感谢Jarbit Lira和CarlosE.López,他们也帮了我很多。