簡單的PHP條件幫助:if($ Var1 =在列表中($ List)和$ Cond2) - 這可能嗎?

[英]Simple PHP Condition help: if($Var1 = in list($List) and $Cond2) - Is this posslbe?


Is this a possible function?

這是一個可能的功能嗎?

I need to check if a variable is existent in a list of ones I need to check against and also that cond2 is true eg

我需要檢查一個變量是否存在於我需要檢查的列表中,並且cond2也是如此

if($row['name'] == ("1" || "2" || "3") && $Cond2){
    doThis();
}

It's not working for me and all I changed in the copy paste was my list and the variable names

它對我不起作用,我在復制粘貼中更改的是我的列表和變量名稱

6 个解决方案

#1


if(in_array($row['name'], array('1', '2', '3')) && $Cond2) {
  doThis();
}

PHP's in_array() docs: http://us.php.net/manual/en/function.in-array.php

PHP的in_array()文檔:http://us.php.net/manual/en/function.in-array.php

#2


You're lookin for the function in_array().

你正在尋找函數in_array()。

if (in_array($row['name'], array(1, 2, 3)) && $cond2) {
    #...

#3


if (in_array($name , array( 'Alice' , 'Bob' , 'Charlie')) && $condition2 ) {
 /* */
} 

#4


use in_array function if(in_array($row['name'], array(1,2,3)) && $cond2){ do ... }

使用in_array函數if(in_array($ row ['name'],array(1,2,3))&& $ cond2){do ...}

#5


$name = $row['name'];
if (($name == "1" || $name == "2" || $name == "3") && $cond2)
{
  doThis();
}

#6


I have something simpler than that, if it's still possible...

我還有比這更簡單的東西,如果還有可能......

if(strpos("1,2,3", $row['name']) !== false) && $Cond2) {
  doThis();
}

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/05/26/724d18ef9cd758cafa9032b481f2f9d5.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com