Example 1 — Check If a Value Is in a List
This example asks whether two different words are in the same array.
<?php
$colors = ["red", "green", "blue"];
var_dump(in_array("green", $colors));
var_dump(in_array("yellow", $colors)); How It Works
- $colors holds three color names.
- "green" is one of the values, so in_array() returns true.
- "yellow" is not in the array, so in_array() returns false.
- var_dump() prints the boolean results so you can see them clearly.

