3v4l.org

run code in 300+ PHP versions simultaneously
<?php $testString = 'scary ghost'; echo "She saw a $testString. It was green!" . PHP_EOL; //embed newline with /n echo "She saw a $testString. It was blue!\n"; $fruit = array('apple', 'banana', 'orange', 'grape'); echo "I ate one $fruit[0] for breakfast, and one $fruit[2] for lunch\n"; // Interpolating an array with a string constant key $name = array('first' => 'George', 'last' => 'Washington'); // Syntax error //echo "The first US President was $name['first'] $name['last']\n"; // Using complex syntax echo "The first US President was {$name['first']} {$name['last']}\n"; $linkData = array('url' =>'http://www.phpfreaks.com', 'name' => 'phpFreaks'); $linkConcatenate = '<a href="' . $linkData['url'] . "'>" . $linkData['name'] . '</a>' . PHP_EOL; $linkInterpolate = "<a href='{$linkData['url']}'>{$linkData['name']}</a>\n"; echo "PHP questions answered at $linkConcatenate <br>\n"; echo "PHP questions answered at $linkInterpolate <br>\n"; class Person { private $name; private $age; private $title; public $summary; public function __construct($name, $title, $age) { $this->name = $name; $this->age = $age; $this->title = $title; $this->summary = $this->__tostring(); } public function __tostring() { return "Name: {$this->name}. Age: {$this->age}. Title: {$this->title}"; } public function getName() { return $this->name; } public function getAge() { return $this->age; } } $bob = new Person('Bob Smith', 'Manager', 31); $sue = new Person('Sue Jones', 'Director', 28); echo "Bob's Summary| {$bob->summary}\n"; echo "Sue's Summary| {$sue->summary}\n"; echo " <table> <tr><th>Employee</th></tr> <tr><td>$bob</td></tr> <tr><td>$sue</td></tr> </table>"; $employees[] = $bob; $employees[] = $sue; echo "\n\n\n"; foreach ($employees as $employee) { echo "{$employee->getName()} is {$employee->getAge()} years old\n"; }
Output for 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.4, 8.3.6
She saw a scary ghost. It was green! She saw a scary ghost. It was blue! I ate one apple for breakfast, and one orange for lunch The first US President was George Washington PHP questions answered at <a href="http://www.phpfreaks.com'>phpFreaks</a> <br> PHP questions answered at <a href='http://www.phpfreaks.com'>phpFreaks</a> <br> Bob's Summary| Name: Bob Smith. Age: 31. Title: Manager Sue's Summary| Name: Sue Jones. Age: 28. Title: Director <table> <tr><th>Employee</th></tr> <tr><td>Name: Bob Smith. Age: 31. Title: Manager</td></tr> <tr><td>Name: Sue Jones. Age: 28. Title: Director</td></tr> </table> Bob Smith is 31 years old Sue Jones is 28 years old
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 She saw a scary ghost. It was green! She saw a scary ghost. It was blue! I ate one apple for breakfast, and one orange for lunch The first US President was George Washington PHP questions answered at <a href="http://www.phpfreaks.com'>phpFreaks</a> <br> PHP questions answered at <a href='http://www.phpfreaks.com'>phpFreaks</a> <br> Bob's Summary| Name: Bob Smith. Age: 31. Title: Manager Sue's Summary| Name: Sue Jones. Age: 28. Title: Director <table> <tr><th>Employee</th></tr> <tr><td>Name: Bob Smith. Age: 31. Title: Manager</td></tr> <tr><td>Name: Sue Jones. Age: 28. Title: Director</td></tr> </table> Bob Smith is 31 years old Sue Jones is 28 years old

preferences:
147.92 ms | 403 KiB | 156 Q