D
D
Daniel2019-01-08 20:46:03
PHP
Daniel, 2019-01-08 20:46:03

How to check if a variable contains any value from an array?

I have the following array with values.

$arr = array('141241241', '5463263', '124124124', '4254512');

And there is a variable $id
How can I implement it through an operator if
If the variable $idcontains at least one value from the array, then outputecho "Найден id - ".$id."<br>";

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaksPaverov, 2019-01-08
@dkotanoff

$arr = array('141241241', '5463263', '124124124', '4254512');
if (in_array("$id", $arr)) {
    echo "Найден ID - ".$id."<br>";
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question