My name is Luka Musin and this is my intention to finaly share some knowledge. I working in centrum holdings company, it is one of the largest company in Czech republic with over 5 000 000 unique web users per month. I work there as a PHP developer.
After I merried my beautiful wife Martina, we decide to work and live Czech republic for a while. That was quite problem for me because i didn't know speak czech language and i didn't know what to do for living there. Then i went to england for 6 month, I bought there Larry Ullman book: "PHP 6 and MySQL 5" , learn it and after 1 year i was ready to start as a junior software developer in small czech company "GREEP".
I will write here about various programming problems, which i meet every day doing my job and hobby , after all to be good programmer you have to love it... so let's start:
Ternary operator is nice way to write if/else statements:
$value = (true) ? 'true' : 'false';
#It is possible to add more condition but they should be in parentheses:
$page = (isset($_GET['advform'])) ? 'advanced-search' : ( $q ? 'results' : 'homepage');
#As from php 5.3 < ternary operator has shorter sintax for assigning variable:
$page = $_GET['page'] ?: false;
Ternary operator is quick almost as a classic if / else statement in condition that input variable dont hold a large amount of data.
if($_GET['page']) {
$page = $_GET['page'] ;
} else {
$page = false;
}
So if $_GET['page'] will hold large amount of data, ternary operator will be drastic slower then classic if/else statement.