I am trying something like this
<input value="<?php echo $_SESSION[empleados][nombre]?>">
The session comes from a query entered in an array
Namely:
<?php
while ($f=mysqli_fetch_array($result)) {
$nombre=$f['nombre'];
$sueldo=$f['sueldo'];
} $datosnuevos=array('id'=>$_GET['id'],'Nombre'=>$nombre,'Sueldo'=>$sueldo);
array_push($arreglo,$datosnuevos);
$_SESSION['empleados']=$arreglo;
?>
For each of the elements in the session, print its name separated by commas between one and the other within the same input.
Namely:
<input value="pepito, juanito, Luis">
I think the way to do this is to include them in an array but can someone tell me how??
You can use the function
implode()
as simple as;The function
implode()
returns a string containing the values of the array.$string (optional): Text string with which we can divide each element of the array within the resulting string.
$array (required): Array that we want to convert to a string.
I edit my answer to add more content;
They can use the following function to do a
multi implode
;Source: https://stackoverflow.com/questions/3899971/implode-and-explode-multi-dimensional-arrays
I think what you're trying to get is something like this:
from a multidimensional array (ok, in session), which saves them. So what you have in session, inside 'employee', is something like this:
so, to get all employees:
And to print the inputs you can do:
Edited: responding to the clarifications in the question
To get something like this:
the process of printing values only varies a little, that is, once you have the array with the employees:
$arr_empleados
, you do the following: