1. Go to this page and download the library: Download molovo/object 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/ */
molovo / object example snippets
use Molovo\Object\DataObject;
// Pass the array of values directly to the constructor
$object = new DataObject([
'some' => [
'awesome' => [
'nested' => 'values'
]
]
]);
// Getting values
echo $object->some->awesome->nested; // returns 'values'
// Setting values
$object->some->awesome = 'code';
// Getting nested values
echo $object->valueForPath('some.awesome'); // returns 'code'
// Setting nested values
$object->setValueForPath('some.awesome.new.values.are', 'awesome');
// Get a pointer to a value (even if it doesn't exist)
$pointer = &$object->getPointer('some');
$pointer = &$pointer->getPointer('value');
$pointer = 'rules';
// Return the values as an array
$object->toArray();
// returns:
// [
// 'some' => [
// 'awesome' => [
// 'new' => [
// 'values' => [
// 'are' => 'awesome'
// ]
// ]
// ],
// 'value' => 'rules'
// ]
// ]
// Merge objects together
$merged = $object->merge(new DataObject(['new' => 'values']);