(see threads http://phpbuilder.com/board/showthread.php?t=10347749,
http://phpbuilder.com/board/showthread.php?t=10347750 and
http://phpbuilder.com/board/showthread.php?t=10347746 for more on this subject).
Try and think logically about what you are doing (you have to do all the thinking because the computer can't do it for you).
You ask "how do I check if the array contains a particular id, and if it does, display the following message, else add the id to the array?" where the array is stored in a session variable.
The answer is right there. Just rephrase it a bit:
"If the array contains a particular ID, then display the message, else add the id to the array".
Which you could write as
if(array contains value) {display message} else {put value in array}
The value is found in $GET['id'], and array in $SESSION['somename'] (which means we'll need to start the session first.
Start the session
if($_SESSION['somename'] contains $_GET['id'])
{
display message
}
else
{
put $_GET['id'] in $_SESSION['somename']
}
What's left is to turn those remaining bits of English into PHP. There are functions for "Start the session", "array contains" and "put in array" (look them up), and the echo statement can display messages.
session_start();
if(in_array($_GET['id'], $_SESSION['somename']))
{
echo "Message";
}
else
{
$_SESSION['somename'][] = $_GET['id'];
}
Two details. First, and more immediate, is that there will be a problem is $SESSION['somename'] doesn't exist yet. If it doesn't, we have to create it first.
if($_SESSION['somename'] doesn't exist)
{
create an array called $_SESSION['somename']
}
session_start();
if(!isset($_SESSION['somename']))
{
$_SESSION['somename'];
}
if(in_array($_GET....
The second is that there is no checking of what sort of thing $_GET['id'] is, or if it even exists.
session_start();
if(!isset($_GET['id']))
{
echo "No id given";
}
else
{
// Here you can check $_GET['id'].
if(!isset($_SESSION['somename'].....
}