dongpiao0731 2014-12-19 13:49
浏览 70
已采纳

基于php中的分隔符从现有数组中创建新数组

I am working at a login script in which the username is an email address and the user can have more than 1 email address with which he can login.

I am creating an array based on a MySQL select LIKE because all the email addresses of the user are on the same column having ## as delimiters.

Array (
    [0] => test@yahoo.com 
    [1] => testabc@yahoo.com##test123@yahoo.com 
    [2] => testing@yahoo.com##abcd@yahoo.com
)

I would like to obtain this array so I can then compare the user input with the exact email address:

Array ( 
    [0] => test@yahoo.com 
    [1] => testabc@yahoo.com 
    [2] => test123@yahoo.com 
    [3] => testing@yahoo.com 
    [4] => abcd@yahoo.com
)

Thank you!

  • 写回答

1条回答 默认 最新

  • douyaju4259 2014-12-19 13:56
    关注
    <?php
    
    $arr = array(); //your array, your values.
    $arrGonnaBe = array(); 
    foreach($arr as $a){
    
        $exp = explode("##",$a);
        if(count($exp)>1){
            foreach($exp as $e){
                array_push($arrGonnaBe,$e);
            }
        }else{
            array_push($arrGonnaBe,$exp[0]);
        }
    } 
    print_r($arrGonneBe);
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C