How can I shorten this PHP if statement?

前端 未结 2 1500
再見小時候
再見小時候 2021-01-25 02:04

I have an if statement, and I need to compare a single string with many different options. The code I post below shows what I mean pretty clear. I know 2 ways of doing this, but

2条回答
  •  [愿得一人]
    2021-01-25 02:20

    http://php.net/manual/en/function.in-array.php

    $centered = array ("contact","report","new");
    if(in_array($Url[0], $centered)) {
        //Do something
    }
    

提交回复
热议问题