3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class Shape { abstract protected function getArea(); public function toStringArea(){ return "The area of the " . get_called_class() . " is ".$this->getArea() . "\n"; } public function toStringPerimeter(){ return "The perimeter of the " . get_called_class() . " is ".$this->getPerimeter() . "\n"; } } class Rectangle extends Shape{ private $l; private $b; public function __construct($l,$b) { $this->l=$l; $this->b=$b; } protected function getArea(){ return $this->l * $this->b; } protected function getPerimeter(){ return 2 * $this->l + 2 * $this->b; } } class Triangle extends Shape{ private $l; private $b; public function __construct($l,$b) { $this->l=$l; $this->b=$b; } protected function getArea(){ return $this->l * $this->b * 0.5; } protected function getPerimeter(){ return $this->l + $this->b + sqrt($this->l * $this->l + $this->b * $this->l); } } class Circle extends Shape{ private $r; public function __construct($r) { $this->r=$r; } protected function getArea(){ return $this->r*$this->r*3.14; } protected function getPerimeter(){ return $this->r*2*3.14; } } echo' <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Show Hide Using Selectbox</title> <style type="text/css"> .box{ padding: 20px; display: none; margin-top: 20px; border: 1px solid #000; } .red{ background: #ff0000; } .green{ background: #00ff00; } .blue{ background: #0000ff; } </style> <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("select").change(function(){ $( "select option:selected").each(function(){ if($(this).attr("value")=="red"){ $(".box").hide(); $(".red").show(); alert("Bam!"); } if($(this).attr("value")=="green"){ $(".box").hide(); $(".green").show(); } if($(this).attr("value")=="blue"){ $(".box").hide(); $(".blue").show(); } }); }).change(); }); </script> </head> <body> <div> <select> <option>Choose Color</option> <option value="red">Red</option> <option value="green">Green</option> <option value="blue">Blue</option> </select> </div> <div class="red box">You have selected <strong>red option</strong> so i am here</div> <div class="green box">You have selected <strong>green option</strong> so i am here</div> <div class="blue box">You have selected <strong>blue option</strong> so i am here</div> '; echo '<p>'; $r = new Rectangle(5, 4); echo $r->toStringArea() . "<br>"; echo $r->toStringPerimeter() . "<p>"; $c = new Circle(10); echo $c->toStringArea() . "<br>"; echo $c->toStringPerimeter() . "<p>"; $t = new Triangle(5, 4); echo $t->toStringArea() . "<br>"; echo $t->toStringPerimeter() . "<p>"; echo ' </body> </html> ';

preferences:
48.93 ms | 402 KiB | 5 Q