Skip to content

Instantly share code, notes, and snippets.

@vikaszeon
Forked from atishgoswami/getter-setter.php
Created November 16, 2015 07:30
Show Gist options
  • Save vikaszeon/affcd941a23ad2f90511 to your computer and use it in GitHub Desktop.
Save vikaszeon/affcd941a23ad2f90511 to your computer and use it in GitHub Desktop.
Array Getter and Setter.
<?php
/**
* Get Current Import Structure Array
*
* @param string $path path to array key
*
* @return void
*/
protected function _getCurrentImportStructure($path = null)
{
//If no path return whole array
if (!$path) {
return $this->_currentImportStructure;
}
$ref = &$this->_currentImportStructure;
$keys = explode('.', $path);
foreach ($keys as $idx => $key) {
if (!is_array($ref)) {
return null;
}
if (!array_key_exists($key, $ref)) {
return null;
}
$ref = &$ref[$key];
}
return $ref;
}//end _getCurrentImportStructure()
/**
* Get Current Import Structure Array
*
* @param string $path path to array key
* @param string $value value
*
* @return void
*/
protected function _setCurrentImportStructure($path = null, $value = null)
{
//If no path return nothing
if (!$path) {
return;
}
$ref = &$this->_currentImportStructure;
$keys = explode('.', $path);
foreach ($keys as $idx => $key) {
if (!is_array($ref)) {
return null;
}
if (!array_key_exists($key, $ref)) {
$ref[$key] = array();
}
$ref = &$ref[$key];
}
$ref = $value;
}//end _setCurrentImportStructure()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment