Les fonctions, 1ere partie
Posté : 05 avr. 2015, 16:03
Salut a tous, j'ai un problème en dimanche ensoleillée avec le premier exercice pour l'impression des élement du tableaux PHP sur le site "CODE ACADEMY"les commentaires sur le forum disent qu'il faut changer de navigateur et bien, je suis passé de mozilla à Chromium en passant par Midori au cas où et je ne pense pas que ce soit là où réside le problème. Je ne trouve pas le code pour imprimer les éléments du tableau "Friends", je pense qu'il est là le problème. Pourriez vous, m'aider? Voici les instructions et le code
Mon Code:Array Functions I
Arrays are a very common thing to use in programming. In fact, array() is actually a function! Good job, you have already used an array function.
Aside from the array() function itself, array_push() is arguably the most common and useful function for manipulating arrays.
array_push() takes two arguments: an array, and an element to add to the end of that array. Here's an example:
$fav_bands = array();
array_push($fav_bands, "Maroon 5");
array_push($fav_bands, "Bruno Mars");
array_push($fav_bands, "Nickelback");
array_push($fav_bands, "Katy Perry");
array_push($fav_bands, "Macklemore");
Another cool array function is count(). Passing an array to count() will return the number of elements in that array. Like this:
print count($fav_bands); // prints 5
Instructions
Use the editor to create an array and use array_push() to add at least 5 elements to it. Once all your elements are added, print out the number of elements in your array.
<?php
// Create an array and push 5 elements on to it, then
// print the number of elements in your array to the screen
$friends= array("tori", "Nessa");
array_push($friends, "Mark");
array_push($friends, "Ariel");
array_push($friends, "Brayden");
array_push($friends, "Luke");
array_push($friends, "Aaron");
print_r ($friends);
?>