Show position 0 of a session variable that contains an array

0

I have a session variable that is called $_session["arrayImagenHecha"] = $arrayImagenHecha . This variable contains an array with images, my problem is that when I want to do an echo to show the position 0 of the arrya I get an error. For example:

   $arrayImagenHecha = completarImagen($array_nombres_imagenes_ordenados,$array_caracteristicas_completas_img);


shuffle($arrayImagenHecha);



$arrayImagenHecha=$_SESSION["arrayImagenHecha"];

echo "<h4 align='center'>Carta del Servidor</h4>";

echo "<table style='border:2px solid black' align='center'";

echo "<tr><td style='border:1px solid black'>
<div class='container_servidor'>
 <div id = 'servCard'class='card' >
    <div class='front'>
          <img class='img' src='assets/reverso/cardBack.jpg'/>
    </div>
    <div class='back'>
        $arrayImagenHecha[0];

    </div>
  </div>
</div>
</td></tr>";



echo "</table>";

This code generates a table with several divs and inside I show the position 0 of the array $arrayImagenHecha[0] . I want to do the same but instead of putting $arrayImagenHecha[0] I want to do this: $_session["arrayImagenHecha"][0]

    
asked by Marc 01.11.2018 в 16:47
source

1 answer

0

If you want to put what is in $arrayImagenHecha in the session variable, you just have to do the following:

$_SESSION["arrayImagenHecha"]=$arrayImagenHecha;

That will make your session variable have a new key called arrayImagenHecha where the array will be found. But make sure that this key does not already exist with other data in the session variable, because you would overwrite it.

Then, to find the first element of the array you can do:

echo $_SESSION["arrayImagenHecha"][0];

And if you are in the context in which $arrayImagenHecha was created, you can use that same variable:

echo $arrayImagenHecha[0];

To concatenate it in your data, you just have to do the following:

echo "<h4 align='center'>Carta del Servidor</h4>";

echo "<table style='border:2px solid black' align='center'";

echo "<tr><td style='border:1px solid black'>
<div class='container_servidor'>
 <div id = 'servCard'class='card' >
    <div class='front'>
          <img class='img' src='assets/reverso/cardBack.jpg'/>
    </div>
    <div class='back'>".$arrayImagenHecha[0]."</div>
  </div>
</div>
</td></tr>";

//resto del código
    
answered by 01.11.2018 в 18:30