1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| //test.php
<?
require ('class_tab.php');
$tableau = new tab();
$tableau->ajoute("V1");
$tableau->ajoute("V2");
$tableau->ajoute("V3");
$tableau->ajoute("V5");
$var2=$tableau->compteur;
for($var=0;$var<$var2;$var++)
{
$tableau->affiche_img($var);
echo "<br>";
}
for($var1=0;$var1<$var2;$var1++)
{
$tableau->affiche_case($var1);
echo "<br>";
}
echo "<br>";
echo "nombre d'objets = ".$tableau->nbObjets();
?>
//class_tab.php
<?
class tab
{
public $compteur;
private $tableau = array ();
public function __construct()
{
$this->compteur = 0;
}
public function ajoute($val)
{
$this->tab[$this->compteur] = $val;
$this->compteur++;
}
public function affiche_case($case)
{
echo 'tab['.$case.']='.$this->tab[$case];
}
public function affiche_img($img)
{
echo "<img src=$this->tab[$img].'.jpg' border='0' />";
}
public function nbObjets()
{
return $this->compteur;
}
}
?> |