![](/img/trans.png)
[英]How to compare a number from an array with the rest of the numbers from that array?
[英]How to compare array of number with string of number?
我進行了高級搜索,我的輸入之一就是復選框。 單擊提交時,返回數組中復選框的值,例如[1,2,3,4]我想將此數組與類型為字符串的表的列進行比較,例如,對於一條記錄,此列值為1,2,並且2,5或3,6或1,2,3用於其他記錄。 我的問題是如何使用此屬性返回記錄? 在此示例中,目標是返回記錄,該記錄存在於字符串列中數組的元素之一。
如果您想使用字符串檢查代碼bellow進行存儲,則可以使用strchr:
$array=array(1,2,3,4);
$string="test1test4tset3";
foreach($array as $key)
{
if(strchr($string,$key))
print $key.' exist';
}
以下代碼將滿足您的要求。
//iterate through your table and let's assume $row is your currently row
foreach ($array as &$value)
if (strpos($row["string"], $value) !== false)
foreach($row as &$rowValue)
echo $rowValue."\n";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.