Grow your CSS skills. Land your dream job.

Last updated on:

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';
?>

Comments

  1. Permalink to comment#

    alert(“wat?”);

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

  3. Tks man! I was looking for it!

  4. Permalink to comment#

    Had an AHA moment when i tried this out for a project i was working on

  5. Permalink to comment#

    Thanks, you saved me some work

  6. So simple :) Thanks!

  7. Permalink to comment#

    Thanks a bunch! Much better solution than I would have done otherwise.

Leave a Comment

Posting Code

  • Use Markdown, and it will escape the code for you, like `<div class="cool">`.
  • Use triple-backticks for blocks of code.
    ``` 
    <div>
      <h1>multi-line block of code</h1>
      <span>be cool yo.</span>
    </div>
    ```
  • Otherwise, escape your code, like <code>&lt;div class="cool"&gt;</code>. Markdown is just easier though.

Current ye@r *

*May or may not contain any actual "CSS" or "Tricks".