View Full Version : Checking if nickname exists in an array

07-30-2012, 10:19 PM
Hi all,

I build a form on which people can enter their credentials on which they can acces the site.
The only problem is that i want the people all have unique nicknames. So i questioned the DB to fill an array $nickname_bestaand with the following values: prof_id_bestaand and nickname_bestaand. To fill the array i use the compact() method like:

$nickname_array[] = compact("prof_id_bestaand","nickname_bestaand");

That's before the form. If i:


it gives me all the values i have registered in the DB.

Now i want to compare the entered nickname ($nickname) value to those in the array. So i call upon the in_array() like:

if(in_array($nickname, $nickname_array))
echo "Uw gekozen nickname bestaat al, kies een andere!!";

BUt everything it does, it doesn't compare the value of the nickname against the nickname_array.

So anyone an idea how to resolve this problem, or where i make the mistake?

Thanks in advance.

07-31-2012, 12:34 PM
something like

$nickname_array = Array("prof_id_bestaand" => "nickname_bestaand");
foreach ($nickname_array as $key => $value){
if ($nickname == $value){
echo "Uw gekozen nickname bestaat al, kies een andere!!";