Hi there,
I am a beginner with PHP and still learning. I have to create a game like MadLibs (word game). I was provided with the function below:
Code: Select all
<?php
function getStoryArray($storyid) {
switch($storyid) {
case 1:
return array ("adjective1", "plural_noun1", "adejctive2", "proper_noun2", "name1", "number1");
case 2:
return array ("proper_noun1", "adjective1", "adverb1", "adjective2", "adjective3", "adjective4");
case 3:
return array ("city1", "proper_noun2", "fruit1", "adjective1");
default: return array();
}
}
?>Using $storyNumber = rand(1, 3); to generate a random number
I am not sure how to retrieve the corresponding array from the above function and then generate a dynamic form using the information in the respective array. I was asked to use foreach loop but not sure how to apply it in this situation.
Can any one help ??
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: