PHP, Shorthand, If..Else using Ternary Operators -


is there oneliner this? nice ternary op?

$f_name = $_session['usr']['f_name']; if(isset($_post['f_name'])) {$f_name = $_post['f_name'];} 

basically "if post sent, show that, if post empty, otherwise grab value session, if post not set or empty"

really splitting hairs here...

looking this:

$f_name = ? ($f_name ? isset($_post['f_name']) : $_session['usr']['f_name']); 

its supposed be:

(conditions) ? true : false    satisfies <--^      ^----> did not satisfy 

so equates into:

$f_name = isset($_post['f_name']) ? $_post['f_name'] : $_session['usr']['f_name']; 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -