0

I've created the following

$usernames = $db->fetchColumn('Select username from profiles');

It creates the following

Array ( [0] => todd [1] => test [2] => brent_test [3] => danny [4] => alyssa [5] => dogg )

I do NOT want to check an array for duplicates in it. I want to check to see if an array has a value in it. If the array ($usernames)does have the value of $var in it, I want it to rerun 'true'. If array ($usernames)does not have the value of $var in it, I want it to return 'false'.

Any suggestions?

Mr. B
  • 2,677
  • 6
  • 32
  • 42
  • 3
    You should check for duplicates in your SQL query instead. – p.s.w.g Jun 09 '14 at 15:58
  • check out this function: http://www.php.net//manual/en/function.array-count-values.php – Brian Glaz Jun 09 '14 at 15:58
  • @john How do I remove the 'duplicate' from this question? It does not ask the same thing as the question you've linked to. Thanks – Mr. B Jun 09 '14 at 16:19
  • If you're looking to check if an array has a value in it use `in_array` http://us2.php.net//manual/en/function.in-array.php – Dan Jun 09 '14 at 16:43
  • @ToddBenrud It's a dupe. The solution you seek is in there. – John Conde Jun 09 '14 at 17:22
  • This is the answer I was looking for. `if (in_array("$username", $usernames)) { echo "$username already exists. Please select a different username."; } else { echo "$username does not exist"; } ` – Mr. B Jun 09 '14 at 18:01

0 Answers0