Posted By

anagaiyahoocom on 03/10/11


Tagged


Versions (?)

Building a String using Concatenation and Ternary Operator


 / Published in: PHP
 

  1. $uri = '';
  2. $uri .= in_array('scheme', $parts) ? (!empty($this->_scheme) ? $this->_scheme.'://' : '') : '';
  3. $uri .= in_array('user', $parts) ? $this->_user : '';
  4. $uri .= in_array('pass', $parts) ? (!empty ($this->_pass) ? ':' : '') .$this->_pass. (!empty ($this->_user) ? '@' : '') : '';
  5. $uri .= in_array('host', $parts) ? $this->_host : '';
  6. $uri .= in_array('port', $parts) ? (!empty ($this->_port) ? ':' : '').$this->_port : '';
  7. $uri .= in_array('path', $parts) ? $this->_path : '';
  8. $uri .= in_array('query', $parts) ? (!empty ($query) ? '?'.$query : '') : '';
  9. $uri .= in_array('fragment', $parts)? (!empty ($this->_fragment) ? '#'.$this->_fragment : '') : '';

Report this snippet  

You need to login to post a comment.