PHP code example of cowshedworks / trees

1. Go to this page and download the library: Download cowshedworks/trees 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/ */

    

cowshedworks / trees example snippets



use CowshedWorks\Trees\TreeDataFactory;

$factory = new TreeDataFactory();
print_r($factory->getTrees());

// prints ['alder', 'birch', 'oak']

$treeData = $factory->build('alder', [
  'circumference' => '22in',
  'height'   => '15ft'
]);

$treeData = $factory->circumference('22in')->height('15ft')->build('alder');


echo $treeData->getPopularName();
// Alder
print_r($treeData->getCommonNames());
// Array
// (
//     [0] => Alder
//     [1] => Common Alder
//     [2] => Black Alder
//     [3] => European Alder
// )
print_r($treeData->getScientificName());
// Array
// (
//     [0] => Alnus glutinosa
// )
echo $treeData->getEstimatedAge();
// 10 years
echo $treeData->getCarbonWeight();
// 36.3 kg
echo $treeData->getCO2SequestrationPerYear();
// 13.31 kg
echo $treeData->getCO2SequestrationToDate();
// 133.09