简体   繁体   English

使一个数组键=>值添加另一个数组中的值

[英]Make an array key => value adding values from another array

I want this array output because I need it for the attendees of the Google_service_calendar_event in PHP: 我需要此数组输出,因为在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 ) ) 

This is my code PHP: 这是我的代码PHP:

    $invitados_inicial = array(array('email' => $correo_del_director));

    foreach ($_SESSION['gcal_correo_aplicantes'] as $correo_aplica) {

        $invitados_inicial['email'] = $correo_aplica;
    }

And this is what I get (NOT what I need): 这就是我得到的(不是我需要的):

    Array ( 
        [0] => Array ( [email] => myemail@gmail.com ) 
        [email] => Array ( 
            [0] => myemail1@gmail.com 
            [1] => myemail2@gmail.com 
            [2] => myemail3@yahoo.com
        ) 
    ) 

Anyways, I don't get my desired output array and I can't my attendees into the Google_service_calendar_event. 无论如何,我没有得到想要的输出数组,我的与会者也无法进入Google_service_calendar_event。 How should I do for getting my disired array output? 我应该如何获得我想要的阵列输出?

You have to clarify the structure of $_SESSION['gcal_correo_aplicantes'] to get the right answer. 您必须弄清楚$_SESSION['gcal_correo_aplicantes']才能获得正确的答案。 In the following, I assumed it was something like : 在下面,我假设它是这样的:

$session = array( "email1@add.com","email2@add.com");

First solution : 第一个解决方案:

<?php
$invitados_inicial=[];
for ($i=0; $i<count($session);$i++) {
    $invitados_inicial[$i] = array( 'email' => $session[$i] );
}
var_dump($invitados_inicial);

Second option : 第二种选择:

<?php
$invitados_inicial=[];
foreach ($session as $correo_aplica) {
    $invitados_inicial[] = array( 'email' => $session[$i] );
}
var_dump($invitados_inicial);

Try this : 尝试这个 :

 $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;
           }
        }

Thanks for your help, you gave me ideas and I could fix it doing this: 感谢您的帮助,您给了我一些建议,我可以通过以下方法对其进行修复:

    $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);
    }

Thanks to Jarbit Lira and Carlos E. López, they help me a lot too. 感谢Jarbit Lira和Carlos E.López,他们也对我有很大帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 仅获取数组的值,并在另一个数组中将其设为新的$ key =&gt; $ value - Get only values of array and make it new $key => $value in another array 将键添加到多个数组,并使用另一个有序数组中的相应值按顺序填充该键的值 - Adding key to multiple arrays and filling the values for that key in order with the corresponding value from another ordered array 在codeigniter中将数组添加到具有键值的另一个数组 - adding array into another array with key value in codeigniter 为另一个数组制作数组值键 - make array value key for another array 创建一个数组,该数组具有另一个数组的值计数,该数组的值作为键,而计数作为值 - Create an array with counts of values from another array with the value as a key and the count as the value 如何将数组中的值附加到另一个数组中的另一个键 - How to attach values from an array to another key in another array 从另一个多维数组向多维数组添加键 - Adding a key to a multidimensional array from another multidimensional array 将一个数组值作为键值对附加到另一个数组php - Append one array values as key value pair to another array php 从 php 中数组的另一个键中查找数组键值 - Find array key value from another key of array in php 我想用另一个数组值添加一个数组键和值 - I want to add one array key and value with another array values
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM