$selected_colours = array('blue','yellow','white');
How can I check if $selected_colours has the value of 'green'?
The in_array() is a PHP inbuilt function that is used to check whether a given value exists in an array or not. It returns either TRUE or FALSE. The function returns TRUE if the given value exists in the array. else return false.
0 0You can check this using in_array() function in PHP
$selected_colours = array('blue','yellow','white'); if( in_array( "green" ,$selected_colours ) ) { echo "green colour exists"; }else{ echo "green colour not exists"; }0 0
in_array ( $value_to_check, $array, $mode );
$mode is an optional parameter. If you need to do an strict check, you pass a $mode = TRUE. By default, $mode = FALSE and no need to check.
// With strict check
echo in_array("green", $selected_colours, true);
// Without strict check
echo in_array("green", $selected_colours);
Please Login to Post the answer