dongteng2534 2017-06-28 17:17
浏览 9
已采纳

什么检查在PHP程序中的条件

Actually I have made small programme in php using simple array and search name from array and my programe given below :

$n = array("Akki","Amesh","Akit","Baa","aaakk");

$hint = "";

$find = "ak";

if ($find !== "") {

    $find = strtolower($find);

    $lwn = strlen($find);

    foreach($n as $gt){     
        if(stristr($find, substr($gt,0,$lwn))){
            if($hint === ''){                   
                $hint .= $gt;
            }else{          
                $hint .= ",$gt";
            }
            }
    }
}
echo ($hint == "") ? "NNN" : $hint ;

My query how to check $hint got data are single & double and how to add comma after got name from array

Like I have searched name using word ak and i got two name Akki and Akit. and its perfect but i want to know how to add comma between that name.

And What does check this condition : ($hint === '')

tell me if anyone know my query.

  • 写回答

4条回答 默认 最新

  • doubianyu7844 2017-06-28 17:31
    关注

    What this code does:

            if($hint === ''){                   
                $hint .= $gt;
            }else{          
                $hint .= ",$gt";
            }
    

    is see if $hint is empty (which it will be the first time the preceding if condition is true, since it is initialized to empty at the beginning). This is used to add a comma only if there is already a value in $hint. The === operator simply compares value and type as opposed to only value comparison when using ==. It is really not necessary here.

    Does that answer your question?

    EDIT: Regarding the comma, as far as I can see the comma is added currently. The code has potential for improvement, but works.

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

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来