Last active
March 31, 2020 13:57
-
-
Save pierrealexaline/fca78b1c49d40fc09bcf5766e3c7039c to your computer and use it in GitHub Desktop.
WCS - Les tableaux (array) en PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| Le fichier contient un tableau multidimensionnel, et on y retrouve bien 3 films, ainsi que 3 acteurs minimum par film. | |
| Une boucle est utilisée pour afficher les films et leurs acteurs | |
| Lorsque tu exécutes le script depuis ton terminal, tu affiches bien : "Dans le film movie_title, | |
| les principaux acteurs sont : name_of_the_actor_1, name_of_the_actor_2, name_of_the_actor_3." | |
| */ | |
| // contruct array | |
| $indianaJonesSaga['Raiders of the Lost Ark2'] = array( 'Harrison Ford', 'Karen Allen', 'Paul Freeman' ); | |
| $indianaJonesSaga['Indiana Jones and the Temple of Doom'] = array( 'Harrison Ford', 'Kate Capshaw', 'Amrish Puri' ); | |
| $indianaJonesSaga['Indiana Jones and the Last Crusade'] = array( 'Harrison Ford', 'Sean Connery', 'Denholm Elliott' ); | |
| $output = ''; | |
| // foreach film has actors | |
| foreach( $indianaJonesSaga as $film => $actors ){ | |
| $output .= "<div>\n"; | |
| $output .= "<p>\n"; | |
| $output .= "Dans le film : \n"; | |
| $output .= "<strong>" . $film . "</strong>\n"; | |
| $output .= " les principaux acteurs sont : \n"; | |
| $output .= "</p>\n"; | |
| $output .= "<ul>\n"; | |
| $output .= "<li>" . $actors[0] . "</li>\n"; | |
| $output .= "<li>" . $actors[1] . "</li>\n"; | |
| $output .= "<li>" . $actors[2] . "</li>\n"; | |
| $output .= "</ul>\n"; | |
| $output .= "</div>\n"; | |
| } | |
| // return output | |
| echo $output; | |
| /* | |
| returned : | |
| Dans le film : Raiders of the Lost Ark2 les principaux acteurs sont : | |
| Harrison Ford | |
| Karen Allen | |
| Paul Freeman | |
| Dans le film : Indiana Jones and the Temple of Doom les principaux acteurs sont : | |
| Harrison Ford | |
| Kate Capshaw | |
| Amrish Puri | |
| Dans le film : Indiana Jones and the Last Crusade les principaux acteurs sont : | |
| Harrison Ford | |
| Sean Connery | |
| Denholm Elliott | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment