so I am having a case where the array is used to store usernames. function presented here is supposed to check if username exists, echo the information and if the username is unique it should add it to the array.
<?php
function check_if_name_exists ($name = NULL)
{
$names = array ("Bob", "Alise", "Karl", "Joe");
if ($name = NULL)
{
echo "you didn't input name";
}
else
{
if (in_array($name , $names) )
{
echo "$name alredy used\n";
}
else
{
echo "name free\n";
$names[] = $name ;
}
}
}
?>
however when I call the function with:
check_if_name_exists();
, or if I add a name that does not exist, always as an output I get:
name free
Any help is welcome. thanks