PHP code example of maplephp / dto
1. Go to this page and download the library: Download maplephp/dto 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/ */
maplephp / dto example snippets
use MaplePHP\DTO\Traverse;
$obj = Traverse::value([
"firstname" => "<em>daniel</em>",
"lastname" => "doe",
"slug" => "Lorem ipsum åäö",
"price" => "1999.99",
"date" => "2023-08-21 14:35:12",
"feed" => [
"t1" => ["firstname" => "<em>john 1</em>", "lastname" => "doe 1"],
"t2" => ["firstname" => "<em>jane 2</em>", "lastname" => "doe 2"]
]
]);
echo $obj->feed->t1->firstname;
// Output: <em>john 1</em>
foreach($obj->feed->fetch() as $row) {
echo $row->firstname;
}
// Output:
// <em>john 1</em>
// <em>jane 2</em>
echo $obj->feed->t1->firstname->strStripTags()->strUcFirst();
// Equivalent to:
// echo $obj->feed->t1->firstname->str()->stripTags()->ucFirst();
// Output: John 1
foreach($obj->feed->fetch() as $row) {
echo $row->firstname->strStripTags()->strUcFirst();
}
// Output:
// John 1
// Jane 2
echo $obj->firstname->strStripTags()->strUcFirst();
// Output: Daniel
echo $obj->price->numToFilesize();
// Output: 1.95 kb
echo $obj->price->numRound(2)->numCurrency("SEK", 2);
// Output: 1 999,99 kr
echo $obj->date->clockFormat("y/m/d, H:i");
// Output: 23/08/21, 14:35