3v4l.org

run code in 300+ PHP versions simultaneously
<?php function changeJob($person, $newjob) { $person['job'] = $newjob; // Change the person's job return $person; } function happyBirthday($person) { ++$person['age']; // Add 1 to the person's age return $person; } $person1 = array( 'name' => 'Tom', 'job' => 'Button-Pusher', 'age' => 34 ); $person2 = array( 'name' => 'John', 'job' => 'Lever-Puller', 'age' => 41 ); // Output the starting values for the people echo "<pre>Person 1: ", print_r($person1, TRUE), "</pre>"; echo "<pre>Person 2: ", print_r($person2, TRUE), "</pre>"; // Tom got a promotion and had a birthday $person1 = changeJob($person1, 'Box-Mover'); $person1 = happyBirthday($person1); // John just had a birthday $person2 = happyBirthday($person2); // Output the new values for the people echo "<pre>Person 1: ", print_r($person1, TRUE), "</pre>"; echo "<pre>Person 2: ", print_r($person2, TRUE), "</pre>";
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
<pre>Person 1: Array ( [name] => Tom [job] => Button-Pusher [age] => 34 ) </pre><pre>Person 2: Array ( [name] => John [job] => Lever-Puller [age] => 41 ) </pre><pre>Person 1: Array ( [name] => Tom [job] => Box-Mover [age] => 35 ) </pre><pre>Person 2: Array ( [name] => John [job] => Lever-Puller [age] => 42 ) </pre>

preferences:
281.81 ms | 406 KiB | 423 Q