I am trying to create the game of sinking the fleet, keeping the ships in arrays. I want to make a table in which the quadrants with the boat differ (by class
). The problem is that when checking, only the first box recognizes me.
This is my code:
<?php
$lancha=array(71);
$destructor=array(18,28);
$submarino=array(33,43,53);
$portaaviones=array(75,76,77,78);
$barcos=array($lancha,$destructor,$submarino,$portaaviones);
session_start();
$_SESSION['barcos']=$barcos;
echo "<table>";
for($a=0;$a<10;$a++){
echo "<tr>";
for($b=0;$b<10;$b++){
if(valida($a.$b))
echo "<td class='verde'>".$a.$b."</td>";
else if(valida($a.$b))
echo "<td class='verde'>".$a.$b."</td>";
else
echo "<td>".$a.$b."</td>";
}
echo "</tr>";
}
echo "</table>";
function valida($p){
foreach ($_SESSION['barcos'] as $key) {
foreach ($key as $q => $value) {
if($p==$value)
return true;
else
return false;
}
}
}