Sto scrivendo un nuovo modulo per integrare in Drupal le ricerche di Google.
Sto leggendo il codice del modulo "search.module" per risalire al suo funzionamento e sfruttarne alcune potenzialità; arrivato però alla funzione "search_get_keys" ho trovato una stringa di codice che non riesco a decifrare: la funzione è questa:
function search_get_keys() {
// Extract keys as remainder of path
// Note: support old GET format of searches for existing links.
$path = explode('/', $_GET['q'], 3);
return count($path) == 3 ? $path[2] : $_REQUEST['keys'];
}
Qualcuno sa spiegarmi che cosa fa l'ultima riga di codice e cioè
count($path) == 3 ? $path[2] : $_REQUEST['keys'];
a che cosa servono il "?" e i ":" ?
So che questa è una domanda che riguarda il php ma non sono riuscito a trovare la risposta da nessuna parte!
Grazie per l'aiuto.
Leggilo come if..then..else
Dal manuale PHP:
" The third group is the ternary operator: ?:. It should be used to select between two expressions depending on a third one, rather than to select two sentences or paths of execution. Surrounding ternary expressions with parentheses is a very good idea."
Espressione ? se_vera : se_falsa;
Matteo
Come al solito il tuo aiuto è stato utilissimo.
Grazie.