Last active
November 16, 2015 07:30
-
-
Save atishgoswami/627d3975ab4edf373ca7 to your computer and use it in GitHub Desktop.
Array Getter and Setter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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