Is there a php equivalent to mySQL's IN?

前端 未结 3 1257
予麋鹿
予麋鹿 2021-01-21 11:28

In writing select statements in mySQL, if I want to pull records where a column value equals one of a number of values, I can say something like this:

SELECT * F         


        
相关标签:
3条回答
  • 2021-01-21 11:40

    yes, It is in_array

    You can check the value if it is in array.

    $categories =array(1,5,7);
    if (in_array($category, $categories))
    {
      //do stuff
    }
    
    0 讨论(0)
  • 2021-01-21 11:54

    See the in_array() function.

    E.g.:

    $list = array(1, 5, 7);
    if (in_array($category, $list)) {
      // do something
    }
    

    Or, more compactly:

    if (in_array($category, array(1, 5, 7))) {
      // do something
    }
    
    0 讨论(0)
  • 2021-01-21 12:03

    Sure in_array, i.e.

    if( in_array( $category, array( 1, 5, 7 ) ) ) {
    
    0 讨论(0)
提交回复
热议问题