Skip to content

Instantly share code, notes, and snippets.

@AndreaBarghigiani
Created January 20, 2015 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndreaBarghigiani/a093158541e9fef4f27c to your computer and use it in GitHub Desktop.
Save AndreaBarghigiani/a093158541e9fef4f27c to your computer and use it in GitHub Desktop.
Esercizio funzione solo_pari()
<?php
//OK per la dichiarazione di un Array
//Ricorda che gli indici partono da 0
$piovono_polpette = array(
"Pollaccione", //indice 0
" Bred", //indice 1
"Diventa", //indice 2
" Gattaccio", //indice 3
" Breddaccio", //indice 4
" che si Pappa Tutti!!!!" //indice 5
);
//Ma non avevi scritto alcuna funzione...
function solo_pari( $arr ){
foreach( $arr as $key => $value ){
if( $key % 2 == 0 ){
echo $value;
}
}
}
//Stampera' soltanto i valori contenuti nell'indice pari
solo_pari( $piovono_polpette );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment