Итак, согласно вашим новым спецификациям и отредактированному вопросу:
<?php
$array = ['red', 'yellow', 'green', 'red'];
$request = ['colour' => 'red'];
// Error counter
$errors = 0;
// If request shows up in the array.. move to next block
if( in_array( $request['colour'], $array ) ){
/* Check how many times this key value shows up,then assign to count
variable.
In this example, $request['colour'] is red
array_count_values($arr) returns an array
$array['red'=> 2,'yellow'=> 1,...], so
show me the **count** in this array at array_key position for "red",
being two.
*/
$count = array_count_values( $array )[ $request['colour'] ];
// if this count is more than 1, increment our error flag for use later
if ($count > 1){
$errors++;
echo "Ut oh, this value shows up more than once in our array";
}
}
или для простоты:
$count = array_count_values( $array )[ $request['colour'] ];
if ($count > 1){ $errors++; }
echo $errors;