如何使检查循环结果默认为 false


How to make check loop result into false by default

>我需要将此循环设置为默认值以允许另一个函数发挥作用。默认情况下如何将所有检查设置为 false?

示例:默认情况下,将下面的所有这些检查($checkGeneral)转换为== false

$resultCatAdd = $catCheckA;
$catCheckA = explode(",", $stockrm['einv_stockrm_cat']);
foreach($catCheckA as &$value) {
    if($value == "General Information") {
        $checkGeneral = true;
    } elseif ($value == "Product Information") {
        $checkProduct = true;
    } elseif ($value == "Warranty Information") {
        $checkWarranty = true;
    } elseif ($value == "Sales Parts") {
        $checkSales = true;
    } elseif ($value == "Customer Information") {
        $checkCustomer = true;
    } elseif ($value == "Internal Information") {
        $checkInternal = true;
    } elseif ($value == "Warehouse Information") {
        $checkWarehouse = true;
    } elseif ($value == "Yearly Reset") {
        $checkYR = true;
    }
}
You could make variable names according strings and then set them to false as below:
<?php
$stockrm['einv_stockrm_cat'] = "General Information,Product Information,Warranty Information,Sales Parts,Customer Information,Internal Information,Warehouse Information,Yearly Reset";
$catCheckA = explode(",", $stockrm['einv_stockrm_cat']);
foreach($catCheckA as $key => $value) {
    $varName = explode(" ", $value);
    $check{ucfirst($varName[0])} = false;
}
foreach($catCheckA as &$value) {
    if($value == "General Information") {
        $checkGeneral = true;
    } elseif ($value == "Product Information") {
        $checkProduct = true;
    } elseif ($value == "Warranty Information") {
        $checkWarranty = true;
    } elseif ($value == "Sales Parts") {
        $checkSales = true;
    } elseif ($value == "Customer Information") {
        $checkCustomer = true;
    } elseif ($value == "Internal Information") {
        $checkInternal = true;
    } elseif ($value == "Warehouse Information") {
        $checkWarehouse = true;
    } elseif ($value == "Yearly Reset") {
        $checkYearly = true;
    }
}