[RESOLU] Les fonctions, 1ere partie

Petit nouveau ! | 3 Messages

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
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.
Mon Code:
<?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);
?>

Mammouth du PHP | 688 Messages

05 avr. 2015, 16:10

tu as bien trouvé la fonction pour imprimer $friends, mais ce n'est pas ce que l'on te demande, à savoir le nombre d'éléments.

Petit nouveau ! | 3 Messages

05 avr. 2015, 16:11

Bonjour merci Tof73, comment je peux imprimer le nombre d'éléments?

Mammouth du PHP | 2278 Messages

05 avr. 2015, 17:15

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
Vanitas vanitatum et omnia vanitas
Mes derniers livres :
Sauvez les Mots chez BoD,
Tous les chemins mènent à ROM chez BoD

Petit nouveau ! | 3 Messages

05 avr. 2015, 18:11

Merci beaucoup j'ai remplacé fav-bands par $friends et cela fonctionne!