public function testLoadArray()
 {
     $this->assertAttributeNotEmpty('array_ob', $this->ap);
     $this->ap->loadArray(array());
     $this->assertAttributeEmpty('array_ob', $this->ap);
     $this->ap->loadArray(array('some', 'value', 'third'));
     $this->assertEquals(3, count($this->ap->toArray()));
 }
示例#2
0
<?php

/**
 * This file is part of the ArrayProperty package.
 *
 * @author Muhammed Mamedov <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
//composer autoload
require __DIR__ . '/../vendor/autoload.php';
use ArrayProperty\ArrayProperty;
//create empty object
$array_property = new ArrayProperty(array());
//empty object verification
var_dump($array_property->toArray());
//not exists
if (!$array_property->exist('firstOne')) {
    echo 'firstOne value not exists<br>';
}
$array_property->firstOne = 'firstvalue';
$array_property->anotherValue = 'anotherOne';
//see new array
var_dump($array_property->toArray());
//access new array elements
echo $array_property->firstOne . '<br>';
echo $array_property->anotherValue . '<br>';
//add more values
$new_add = array('person' => array('name' => 'Muhammed', 'lastname' => 'Mamedov'), 'stuff' => array('read' => 'books', 'hobby' => 'fish'));
//add above array
示例#3
0
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
//composer autoload
require __DIR__ . '/../vendor/autoload.php';
use ArrayProperty\ArrayProperty;
//sample array data
$sample = array('app' => array('log_dir' => '/log/path', 'debug' => false, 'log' => true, 'version' => '2.3', 'deep' => array('inner' => 'some value', 'level' => '2')), 'database' => array('host' => 'localhost', 'user' => 'test', 'password' => 'testPwd=!', 'name' => 'localdbname'));
echo '<h3>print_r $sample array:</h3><pre>';
print_r($sample);
echo '</pre>';
/**
 * Construct ArrayProperty
 */
$a = new ArrayProperty($sample);
/**
 * Access any value, 'leaf'
 */
echo '<h3>Accessing values:</h3>';
echo '$a->app->log_dir: ' . $a->app->log_dir . "<br/>" . "\n";
echo '$a->app->deep->inner.: ' . $a->app->deep->inner . "<br/>" . "\n";
echo '$a->database->name: ' . $a->database->name . "<br/>" . "\n";
echo 'var_dump($a->app->log): <br/>';
var_dump($a->app->log);
/**
 * Check if leaf/node exists
 */
echo '<h3>Check if leaf/node exists:</h3>';
echo '$a->database->exist(\'host\'): ' . "<br/>" . "\n";
var_dump($a->database->exist('host'));