A Web Design Community curated by Chris Coyier

A little dab'll do ya

Code Snippets

Home » Code Snippets » PHP » PHP Array Contains Submit one!

PHP Array Contains

Check if value is in array and outputs Yes or No

<?php
$names = array( 'Bob', 'Jim', 'Mark' );
echo 'In Array? ';
if (in_array(‘foo’, $names))
   echo 'Yes';
else
   echo 'No';
?>

Subscribe to The Thread

  1. Jimbo says:

    alert(“wat?”);

  2. Dan says:

    Nice! Exactly what I was looking for.
    I found it helpful.
    Thanks!

  3. Marcius says:

    Tks man! I was looking for it!

It's Your Turn

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
--- The Management ---