PHP code example of thrashzone13 / visitor
1. Go to this page and download the library: Download thrashzone13/visitor library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
thrashzone13 / visitor example snippets
php
$visitor = (new Visitor)
->add(fn(Circle $circle) => pi() * $circle->getRadius() * $circle->getRadius())
->add(fn(Square $square) => $square->getSide() * $square->getSide())
->add(fn(Rectangle $rectangle) => $rectangle->getWidth() * $rectangle->getHeight());
php
$totalArea = 0;
foreach ($shapes as $shape) {
$totalArea += $visitor->visit($shape);
}