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

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -