2017-10-19 1 views
0

ich dieses Array ausgegeben werden soll, weil ich es für die Teilnehmer des Google_service_calendar_event in PHP benötigen:Machen Sie ein Array Schlüssel => Wert Werte von einem anderen Array hinzufügen

Array ( 
     [0] => Array ([email] => [email protected]) 
     [1] => Array ([email] => [email protected]) 
     [2] => Array ([email] => [email protected]) 
     [3] => Array ([email] => [email protected])) 

Das ist mein PHP-Code:

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

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

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

Und das ist, was ich (nicht das, was ich brauche):

Array ( 
     [0] => Array ([email] => [email protected]) 
     [email] => Array ( 
      [0] => [email protected] 
      [1] => [email protected] 
      [2] => [email protected] 
     ) 
    ) 

Anyways, ich habe nicht meine gewünschte Ausgabe Array und ich kann meine Teilnehmer nicht in den Google_service_calendar_event aufnehmen. Wie sollte ich meine gewünschte Array-Ausgabe erhalten?

+1

Hallo, versuchen '$ invitados_inicial [] = [ 'E-Mail' => $ correo_aplica];' – marv255

+0

@ marv255, funktioniert es nicht :( –

Antwort

0

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; 
      } 
     } 
+0

es nicht :( –

+0

arbeiten, was die Ausgabe ist –

+0

dies ist das? Ausgabe: Array ([0] => Array ([email] => [email protected]) [1] => Array ([email] => Array ([0] => [email protected] [1] = > [email protected] [2] => [email protected]))) –

1

Sie haben die Struktur von $_SESSION['gcal_correo_aplicantes'] zu klären, um die richtige Antwort zu bekommen. Im Folgenden habe ich angenommen, es war so etwas wie:

$session = array("[email protected]","[email protected]"); 

Erste Lösung:

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

Zweite Option:

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

$ _SESSION ['gcal_correo_aplicantes'] ist eine POST-Variable eines Mehrfachauswahl-Input (HTLM select mit mehreren Auswahl einer einfachen Liste) Wenn ich eine print_r dieser Variable mache, bekomme ich folgendes: array (1) {[0] => array (3) {[0] => string (27) "[email protected] "[1] => string (27)" [email protected] "[2] => string (23)" [email protected] "}} und das habe ich mal ausprobiert d es funktioniert nicht :( –

0

Danke für deine Hilfe, du hast mir Ideen und ich konnte Repariere es dabei:

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

Dank Jarbit Lira und Carlos E. López helfen sie mir auch sehr.

Verwandte Themen