Php Programming Code Examples
Php > Function Handling Code Examples
User Function Intro
User Function Intro
<?php
$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
// )
?>