Is there any PHP function like MYSQL IN?
We can check i开发者_开发问答n MYSQL for example SELECT * FROM smth WHERE id IN(1,2,3)
and select things where id 1, 2 or 3.
Is it possible to do it in PHP? To change this line:
if($_GET['mi'] == 4 || $_GET['mi'] == 5) {
do_something();
}
into a shorter line? Like if($_GET['mi'] in(1,2,3)) { true(); }
Thanks.
Sure, use in_array
:
if(in_array($_GET['mi'], array(4, 5)) { do_smth(); }
$in = array(1,2,3);
if(in_array($_GET['mi'], $in)) { true(); }
if(in_array($_GET['mi'), array(4, 5)) { do_smth(); }
Use PHP's in_array function. You just need to create an array first.
$arr = array(1,2,3);
if (in_array($_GET['mi'], $arr))
{
true();
}
精彩评论