检查 PHP 中的数组元素


check array element in PHP

PHP可以检查数组中的某个元素是否包含一些单词吗?

例如:

        `[order_product_code] => I9300_cash397096569`

想要检查元素是否包含现金字。

如果$array是你的元素数组:

foreach($array as $key=>$element) {
  if(strpos('cash',$element) !== FALSE) echo "$key: ok";
  else echo "$key: ko";
}