Using the array_map() Function : array_map « Data Structure « PHP






Using the array_map() Function

 
<?php

    function my_callback($var) {

        echo "Value: $var<BR>";
        return strtoupper($var);

    }

    $myarray = array("hello", "this", "is", "a", "callback!");
    $newarray = array_map("my_callback", $myarray);

    echo "<PRE>";
    print_r($newarray);
    echo "</PRE>";
?>
  
  








Related examples in the same category

1.Applying Functions to Array Elements Using array_map()
2.Using array_map() and array_walk() together