Preg_match in switch case in PHP? -


this question has answer here:

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

Popular posts from this blog

PHP while loop dynamic rowspan -

timer - Java TimerTask cancel -

android - How to read a column value in parse.com without accessing an object or a pointer -