Answers for "Checking if a value exists in array php"

PHP
22

check if array has value php

$myArr = [38, 18, 10, 7, "15"];

echo in_array(10, $myArr); // TRUE
echo in_array(19, $myArr); // TRUE

// Without strict check
echo in_array("18", $myArr); // TRUE
// With strict check
echo in_array("18", $myArr, true); // FALSE
Posted by: Guest on January-21-2020
0

php check if value exists in multidimensional array

// 1d array
in_array('something', $array);

// 2d array
array_column($multi_array, 'your_column');

/**
0 => ['hi'=>0, 'your_column'=>1, 'hi'=>0, 'your_column'=>3]
will be
[1, 3]
and then you can apply the in_array function on that new array ^
*/
Posted by: Guest on July-14-2020

Code answers related to "Checking if a value exists in array php"

Browse Popular Code Answers by Language