- debut tableau<br>
- <?php
- $test[0] = "a";
- $test[1] = "b";
- $test[2] = "d";
- $test[3] = "e";
- $test[4] = "f";
- //AFFICHAGE TABLEAU
- for ($i=0;$i<count($test);$i++){
- echo $test[$i]."<br>";
- }
- echo "<br>";
- $test = tabAjoutLigne($test,2,"HELLO !!");
- echo"<br>";
- echo "tableau final<br>";
- for ($i=0;$i<count($test);$i++){
- echo $test[$i]."<br>";
- }
- ?>
- </body>
- </html>
-
-
- <?php
-
- // FUNCTION EPUREE
-
- function tabAjoutLigne($tableau,$ligne,$contenu){
- $limit = $ligne + 1;
- for($i=0;$i<$limit;$i++){$temp1[] = $tableau[$i];}
- for($i=$limit;$i<count($tableau);$i++){$temp2[] = $tableau[$i];}
- unset($tableau);
- for($i=0;$i<count($temp1);$i++){$tableau[] = $temp1[$i];}
- $tableau[]= $contenu;
- for($i=0;$i<count($temp2);$i++){$tableau[] = $temp2[$i];}
- return $tableau;
- }
-
-
- // function qui permet d'ajouter une ligne vide dans un tableau
- // parametres : $tableau -> tableau à passer
- // $ligne -> int qui permet de choisr après kel position on insert
- // !!!! L'index va de 0 -> +infini
- // $contenu -> Valeur à mettre dans la nouvelle ligne du tableau
- function tabAjoutLigne($tableau,$ligne,$contenu){
- // REMPLISSAGE PREMIER TABLEAU TEMP1
-
- $limit = $ligne + 1;
- for($i=0;$i<$limit;$i++){
- $temp1[] = $tableau[$i];
- }
-
- // REMPLISSAGE SECOND TABLEAU TEMP2
- for($i=$limit;$i<count($tableau);$i++){
- $temp2[] = $tableau[$i];
- }
- //DESTRUCTION DU TABLEAU D'ORIGINE
- unset($tableau);
- //AFFICHAGE TEMP1 retirez les commentaires si vous voulez voir
- /*
- echo"<br>";
- echo "tableau temp1<br>";
- for ($i=0;$i<count($temp1);$i++){
- echo $temp1[$i]."<br>";
- }
- // AFFICHAGE TEMP2 retirez les commentaires si vous voulez voir
- echo"<br>";
- echo "tableau temp2<br>";
- for ($i=0;$i<count($temp2);$i++){
- echo $temp2[$i]."<br>";
- }
- */
-
- // RECREATION DU TABLEAU D'ORIGINE AVEC LES VALEURS DE TEMP1
- for($i=0;$i<count($temp1);$i++){
- $tableau[] = $temp1[$i];
- }
- //ajout d'une ligne vide
- $tableau[]= $contenu;
- // RECREATION DU TABLEAU D'ORIGINE AVEC LES VALEURS DE TEMP2
- for($i=0;$i<count($temp2);$i++){
- $tableau[] = $temp2[$i];
- }
-
- return $tableau;
- }
- ?>
debut tableau<br>
<?php
$test[0] = "a";
$test[1] = "b";
$test[2] = "d";
$test[3] = "e";
$test[4] = "f";
//AFFICHAGE TABLEAU
for ($i=0;$i<count($test);$i++){
echo $test[$i]."<br>";
}
echo "<br>";
$test = tabAjoutLigne($test,2,"HELLO !!");
echo"<br>";
echo "tableau final<br>";
for ($i=0;$i<count($test);$i++){
echo $test[$i]."<br>";
}
?>
</body>
</html>
<?php
// FUNCTION EPUREE
function tabAjoutLigne($tableau,$ligne,$contenu){
$limit = $ligne + 1;
for($i=0;$i<$limit;$i++){$temp1[] = $tableau[$i];}
for($i=$limit;$i<count($tableau);$i++){$temp2[] = $tableau[$i];}
unset($tableau);
for($i=0;$i<count($temp1);$i++){$tableau[] = $temp1[$i];}
$tableau[]= $contenu;
for($i=0;$i<count($temp2);$i++){$tableau[] = $temp2[$i];}
return $tableau;
}
// function qui permet d'ajouter une ligne vide dans un tableau
// parametres : $tableau -> tableau à passer
// $ligne -> int qui permet de choisr après kel position on insert
// !!!! L'index va de 0 -> +infini
// $contenu -> Valeur à mettre dans la nouvelle ligne du tableau
function tabAjoutLigne($tableau,$ligne,$contenu){
// REMPLISSAGE PREMIER TABLEAU TEMP1
$limit = $ligne + 1;
for($i=0;$i<$limit;$i++){
$temp1[] = $tableau[$i];
}
// REMPLISSAGE SECOND TABLEAU TEMP2
for($i=$limit;$i<count($tableau);$i++){
$temp2[] = $tableau[$i];
}
//DESTRUCTION DU TABLEAU D'ORIGINE
unset($tableau);
//AFFICHAGE TEMP1 retirez les commentaires si vous voulez voir
/*
echo"<br>";
echo "tableau temp1<br>";
for ($i=0;$i<count($temp1);$i++){
echo $temp1[$i]."<br>";
}
// AFFICHAGE TEMP2 retirez les commentaires si vous voulez voir
echo"<br>";
echo "tableau temp2<br>";
for ($i=0;$i<count($temp2);$i++){
echo $temp2[$i]."<br>";
}
*/
// RECREATION DU TABLEAU D'ORIGINE AVEC LES VALEURS DE TEMP1
for($i=0;$i<count($temp1);$i++){
$tableau[] = $temp1[$i];
}
//ajout d'une ligne vide
$tableau[]= $contenu;
// RECREATION DU TABLEAU D'ORIGINE AVEC LES VALEURS DE TEMP2
for($i=0;$i<count($temp2);$i++){
$tableau[] = $temp2[$i];
}
return $tableau;
}
?>