dpdp42233
dpdp42233
2017-11-04 17:26

在多维数组中查找匹配项

  • php
  • arrays

I have an array that contains phone numbers in different format:

$myArr[0][0] == '122-33-2222';
$myArr[1][0] == '(122) 433-5555';
$myArr[2][0] == '122 644.8888';

I need to check if another number is in that array. I assume I need to loop through array and strip all non-numeric values before I compare.

$findNumber = 122.433.5555;
$varPhone = preg_replace("/[^0-9,.]/", "", $findNumber);

foreach ($myArr AS $phone) {
   if (preg_replace("/[^0-9,.]/", "", $phone) == $varPhone) {
      echo "found";
   } else {
      echo "not found";
   }
}

I think I'm close but it's not quite there. What am I missing?

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答

为你推荐