I try to make a multidimensional array with PHP, to simulate the chairs of a theater. At first I want to do it with letters but then I want to put ICONS instead of them, the idea is to simulate the purchase, reservation or release of a seat in the theater.
At the moment in the traversal of the for
, I filled the content <li>
with a direct value that is 1, I have the following code.
<?php
$sillas = array(
'A'=>array("libre","libre","libre","libre","libre"),
'B'=>array("libre","libre","libre","libre","libre"),
'C'=>array("libre","libre","libre","libre","libre"),
'D'=>array("libre","libre","libre","libre","libre"),
'E'=>array("libre","libre","libre","libre","libre"));
foreach ($sillas as $key => $value) {
echo "<ul id='sillas'>";
echo "$key";
for ($indice=0; $indice < count($value); $indice++) {
echo "<li>1</li>";
}
echo "</ul>";
}
?>
But when changing the value 1 <li>
for the content of the variable, $value
then I receive an error in the browser, which I do not understand why.
<?php
$sillas = array(
'A'=>array("libre","libre","libre","libre","libre"),
'B'=>array("libre","libre","libre","libre","libre"),
'C'=>array("libre","libre","libre","libre","libre"),
'D'=>array("libre","libre","libre","libre","libre"),
'E'=>array("libre","libre","libre","libre","libre"));
foreach ($sillas as $key => $value) {
echo "<ul id='sillas'>";
echo "$key";
for ($indice=0; $indice < count($value); $indice++) {
echo "<li>$value</li>";
}
echo "</ul>";
}
?>
I appreciate if you can help me, because the idea is after showing the chairs or the stalls, to be able to choose from the form the letter and number of the stall to buy, but additionally, I believe that with javascript, superimpose a <div>
that indicates when the stall is purchased or reserved, additionally, if it is in one of those two states, it can display an alert that prevents it from being re-booked or purchased. I don't know if I make myself understood with the idea.
Wrap the code in the part where the content is displayed. You are trying to display
$value
, which corresponds toarray
the row you are displaying (hence the "Array to string conversion" message ).Use
$value[$indice]
where you want to display the value. Also, I think the first element of the row should also be a<li></li>
to maintain the structure.