$av = array( "the ","a" ,"that ","this "); array_walk($av, create_function( '$v,$k' ,'$v = $v ."mango" ;')); print_r($av); / / for PHP 3 use var_dump() / / outputs: / / Array / / (/ / [0] = the mango / / [1] = a mango / / [2] = that mango / / [3] = this mango / /) / / an array of strings ordered from shorter to longer $sv = array("small" ,"larger" ,"a big string" ,"it is a string thing"); print_r($sv); / / outputs: / / Array / / (/ / [0] = small / / [1] = larger / / [2] = a big string / / [3] = it is a string thing / /) / / sort it from longer to shorter usort($sv, create_function('$a,$b' ,'return strlen($b) - strlen($a) ;')); print_r($sv); / / outputs: / / Array / / (/ / [0] = it is a string thing / / [1] = a big string / / [2] = larger / / [3] = small / /)
?php $av = array( "la ","une" ,"cette ","une certaine "); array_walk($av, create_function( '$v,$k' ,'$v = $v ."maison" ;')); print_r($av); / / En PHP 3 utilisez var_dump() ?php $av = array("la" ,"une ","cette" ,"une certaine "); array_walk($av, create_function(' $v,$k' ,'$v = $v ."maison" ;')); print_r($av); / / En PHP 3 utilisez var_dump() / / affiche: / / Array / / (/ / [0] = la maison / / [1] = une maison / / [2] = cette maison / / [3] = une certaine maison / /) / / un tableau de chaîne classé par taille $sv = array("petite" ,"moyenne" ,"tres longue" ,"vraiment tres longue"); print_r($sv); / / affiche: / / Array / / (/ / [0] = petite / / [1] = moyenne / / [2] = tres longue / / [3] = vraiment tres longue / /) / / Tri par ordre de taille décroissant usort($sv, create_function('$a,$b' ,'return strlen($b) - strlen($a) ;')); print_r($sv); / / outputs: / / Array / / (/ / [0] = vraiment tres longue / / [1] = tres longue / / [2] = moyenne / / [3] = petite / /)?