PHP code example of coercive / arraypath

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

    

coercive / arraypath example snippets


use Coercive\Utility\ArrayPath\ArrayPath;

# EXAMPLE
$example_array = [
	'1' => [
		'2' => [
			'3' => [
				'content'
			]
		]
	]
];

# INIT OBJECT
$handler = ArrayPath::init($example_array);

# RETRIEVE CONTENT
$content = $handler->get('1.2.3');
$content = $handler->get('1.2.3.4', '-- null or not exist --');

# VERIFY PATH EXIST
if($handler->has('1.2.3')) {
	// ...
}

# OR get and check in same time
$content = $handler->get('1.2.3.4', null, $exist);
if(!$exist) {
	// ...
}

# SET VALUE
$handler->set('1.2.3', ['new-content']);

# DELETE PATH
$handler->delete('1.2.3');

# RESET
$handler->reset();

# OPTION : custom separator
$handler->setSeparator('@');
$content = $handler->get('1@2@3');