Using $_SESSION of PHP to do a simple Phonebook
$_SESSION of PHP is a assosiative array that contain session variables available for the current script. We could use this $_SESSION array to store contacts from our phonebook.
· Our phone book will have the next condition:
If the name you entered already exists in the phonebook and no phone number is indicated, the entry corresponding to that name will be removed from the phonebook.
First, we need create the inputs where the user will send her name and number phone:
The next step is to obtain the data entered by the user and for this we will use the $_SESSION array.
First we need create two variables to keep the name and phone recieved:
Then we must initialize this array with the function sesion_start(). If you don’t write this line can’t use $_SESSION.
How $_SESSION is an asosiative array we could use the key to store the phone and the value to store the name. Before we will change the number to string
so that the key and the value have the same type.
so that the key and the value have the same type.
After creating our associative array we would check if a name has been entered and chek if the name you entered already exists in the phonebook and no phone number is indicated. Then that entry will be deleted using unset() function of PHP. But if everything is correct a new contact will be added to the phonebook.
Comentarios
Publicar un comentario