arrays - Shorthand IF statement in PHP -
i'm wondering if next possible. want if statement wrote below in 1 line (ternary).
i want utilize ternary(shorthand php code) in array curl.
form info example:
$_post['data'] = 'sometextrighthereisgood:this want"; //user input example.
if statement:
if(isset($_post['data'])) { $string = explode(':', $_post['data']); $string = $string[1]; //contains "this want" } else { $string = null; }
array example:
$arr = array('text' => $string); //example utilize in array.
any ideas if it's possible?
kind regards alex
try one:
list(,$string) = isset($_post['data']) ? explode(':', $_post['data']) : array(null,null) ;
php arrays if-statement ternary
No comments:
Post a Comment