Example 1: in_array php
<?php
$os = array("Apple", "Banana", "Lemon");
if (in_array("Apple", $os)) {
echo "Yeah. Exist Apple";
}
if (!in_array("Buleberry", $os)) {
echo "Oh, Don't Exist Blueberry!!!";
}
?>
Example 2: php array has value
$myArr = [38, 18, 10, 7, "15"];
echo in_array(10, $myArr);
echo in_array(19, $myArr);
echo in_array("18", $myArr);
echo in_array("18", $myArr, true);
Example 3: in_array
<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
?>
Example 4: php value in array
in_array ( mixed $needle , array $haystack , bool $strict = false ) : bool
Example 5: in_array in php
in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] ) : bool
echo in_array("18", $myArr);
echo in_array("18", $myArr, true);
Example 6: php arrays
#Arrays
<?php
$people = array('Kevin', 'Jeremy ', 'Sara');
$ids = array(23, 55, 12);
$cars = ['Honda', ' Toyota', 'Ford'];
$cars[3] = ' Audi';
$cars[] = ' Chevy';
echo $people[1];
echo $ids[1];
echo $cars[1];
echo $cars[3];
echo $cars[4];
echo count($cars);
print_r($cars);
echo var_dump($cars);
$people1 = array('Kevin' => 35, 'Jeremy' => 23, 'Sara' => 19);
$ids1 = array(23 => 'Kevin', 55 => 'Jeremy', 12 => 'Sara');
echo $people1['Kevin'];
echo $ids1[23];
$people1['Jill'] = 44;
echo $people1['Jill'];
print_r($people1);
var_dump($people1);
$cars2 = array(
array('Honda',20,10),
array('Toyota',30,20),
array('Ford',23,12)
);
echo $cars2[1][0];
?>