Preg_match in switch case in PHP? -
this question has answer here:
- regexp in switch statement 3 answers
i making switch function in php , wonder if possible make 1 of cases that:
switch($message){ case 'hi': $output = $jsonwelcome; break; case preg_match('/start/', $message): $output = $jsonhelp; break; }
i want execute last case when $message example: "project start" or "start project". think that's because preg_match return 0 or 1. there way make code works?
switch($message){ case 'hi': $output = $jsonwelcome; break; case (preg_match('/start/', $message) ? true : false): $output = $jsonhelp; break; }
should work fine.
example working code: http://sandbox.onlinephpfunctions.com/code/99ab518718ce9488277619a33dbfdf353f0c2316
Comments
Post a Comment