3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function square($n) { // Check if the item is a number if(is_numeric($n)) $n = ($n * $n); // Yes, square it else $n = "Not a number"; // No, replace with this } // Initialize the array $array = array(0, 48, 22, 90, 44, 9, 222, 'Iamzheasshole', 101); // Walk through the array, called the square function for every item array_walk($array, 'square'); // Output the array print_r($array);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [0] => 0 [1] => 48 [2] => 22 [3] => 90 [4] => 44 [5] => 9 [6] => 222 [7] => Iamzheasshole [8] => 101 )