-1

私はこれを持っていますvar_dump($productId):

string(1) "9"

string(2) "11"

string(2) "12"

string(2) "17"

string(2) "18"

ここで、たとえば、id 18 と 17 に対して function_x を実行しないようにしたいので、次のようなものを作成します。

$test=array('18','17');
if(!in_array($test,array($productId))){}

しかし、機能していないようです。アイデアは、18歳だけで作りたい場合です。

$test=18;
if($test != $productId){}

これは機能していますが、複数の番号/ ID に対してどのように行うのですか?

前もって感謝します!

4

2 に答える 2

1

他の答えはあなた$productIdが配列であると仮定していると思います。foreachか何かの中でvar_dump()を実行していると思います。

if(17 != $productId && 18 != $productId)
{
    // If $productId is not 17 and is not 18.
}

// Alternatively, if you want to add more IDs to ignore, you could use in_array.
$ignore = array(17,18,19,20);

if(false == in_array($productId,$ignore))
{
    // If $productId is not in the ignore array.
}
于 2013-02-08T08:39:07.827 に答える
0

$productId一度に 1 つずつ文字列として取得する場合:

if(!in_array($productId,$test)) {
    // execute function
}

$productIdが配列の場合:

$test=array('18','17');
foreach ($productId as $id) {
    if(!in_array($id,$test)) {
        // execute function
    }
}
于 2013-02-08T08:11:33.293 に答える