Search the Community
Showing results for tags 'program'.
-
I am a university student. What are the sample programs we can do with php? Can those who have php codes share about this subject? Thanks in advance
- 2 replies
-
- php
- computer-science
-
(and 1 more)
Tagged with:
-
I have been tasked to create a small program in any language I know, which is PHP. It will be a console app (I can't install a LAMP stack etc) and it has to: Allow one of six minibeasts to be selected from a menu Enter and store the name and grid co-ordinates of the selected minibeast Display how often each minibeast was found Display the minibeasts found in each grid co-ordinate So far in PHP I have got a welcome screen, then some of the menu from which they can input what minibeast they want to select information for (sort of). I have the actual menu worked out, it's a simple "echo" after all, but I need to work out how to execute different code based on their input. This is my main file: require_once 'functions.php'; require_once 'config.php'; welcome(); // Adds the welcome message to the program menu(); // Adds the selection menu to the console app getUserInput(); This is functions.php with all my functions: <?php // This holds all of the functions for the // program // Welcome function (just text really) function welcome(){ echo " Welcome to the console application. "; echo " To begin using the program, type a number from the list below and then press \"ENTER\" to execute it. "; echo " For help, type \"help\" and execute it, for credits type \"credits\" and execute and for prog. info type \"info\". Version $vernumber "; } // Next is the selection menu function menu(){ echo " Please execute a number from below: 1. Slug 2. Centipede 3. Ladybird 4. Snail 5. Woodlouse 6. Worm 7. Exit "; } // Add the input catcher function getUserInput(){ fwrite(STDOUT, "Enter your choice\n"); $selected = fgets(STDIN); if ($selected = "1"){ echo "hi"; } elseif($selected = "2"){ } } ?> This is where the problems start. I take their input as $selected, but the if statement is for some reason not working. Then I need to work out how to execute the function again if they enter nothing. Could this be accomplished in a while.. loop? Thanks a lot