PHP code example of mmamedov / array-property

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

    

mmamedov / array-property example snippets


$sample =
    array(
        'app' => array(
            'log_dir' => '/log/path',
            'debug' => false,
            'log' => true,
            'version' => '2.3',
            'deep' => array(
                'inner' => 'some value',
                'level' => '2'
            )
        ),
        'my node' => 'some value'
    );

$a = new ArrayProperty($sample);
echo $a->app->log_dir;      //outputs /log/path
echo $a->app->deep->inner;  //outputs 'some value'

//convert to array
$deep = $a->app->deep->toArray();
print_r($deep);             //outputs deep as array;

//check if value exists:
$a->app->exist('log_dir')   //returns true

$prop = new ArrayProperty(array());
$new = array(1 => 'apple', 2 => 'orange', 3 => 'olive', 4 => 'grapes', 'multi'=>array('key'=>'value'));
echo $prop->loadArray($new)->{1}; //outputs "apple"
echo $prop->multi->key;           //outputs "value"

$prop->myNewNode = "myValue";   //you can assign arrays as well.
echo $prop->myNewNode;          //outputs 'myValue';
//overwrite existing elements
$prop->{1} = "banana"; 
echo $prop->{1};                //now outputs "banana" instead of "apple"

$prop->setMode(ArrayProperty::OBJECT_MODE);
var_dump($prop->myNewNode);     //returns ArrayProperty object

$prop->setMode(ArrayProperty::MIXED_MODE);
var_dump($prop->myNewNode);     //returns "myValue" which was set before