doue2666 2010-09-14 15:18
浏览 21
已采纳

多维关联数组电子邮件检查

I have an array multidimensional associative array.

Array
(


[0] => Array
        (
            [username] => uname1
            [name] => fullname1
            [email] => uname1@email.com

        )
[1] => Array
        (
            [username] => uname2
            [name] => fullname2
            [email] => uname2

        )
[2] => Array
        (
            [username] => uname3
            [name] => fullname3
            [email] => uname3@email

        )
[3] => Array
        (
            [username] => uname4
            [name] => fullname4
            [email] => uname4@

        )

}

It should validate email address using the regular expression.The return array should consists of an array with only valid array.The array should be

Array
(


[0] => Array
        (
            [username] => uname1
            [name] => fullname1
            [email] => uname1@email.com
}

since [1,2,3] have invalid email address.

  • 写回答

5条回答 默认 最新

  • dongmo3413 2010-09-14 15:46
    关注

    Each of the answers is valid, and deserve some upvotes. FWIW, I tried running each over 10000 iterations, and measured the elapsed time using microtime(true).

    • @Gumbo's solution, array_filter()/filter_var(): 0.631 sec.

    • @Gordon's solution, array_filter()/filter_var() w/anon function: 0.620 sec.

    • @mck89's solution, array_filter()/preg_match(): 0.307 sec.

    • @Alexander.Plutov's solution, foreach()/preg_match(): 0.193 sec.

    edit: I re-tested with a more robust email regex.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数