Last active
August 29, 2015 14:15
-
-
Save kijtra/78c54a12cfbf3c4432f3 to your computer and use it in GitHub Desktop.
#PHP 変数のSet/Get用関数
This file contains 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 | |
function vars($keys = null, $value = null) | |
{ | |
static $values = array(), $buffer = array(); | |
if (empty($keys)) { | |
return $values; | |
} | |
elseif (is_string($keys)) { | |
//$keys = strtolower($keys); | |
if (null !== $value) { | |
if (false !== strpos($keys, '.')) { | |
$ex = explode('.', $keys); | |
$current = $ex[0]; | |
$data = array(); | |
$ref =& $data; | |
foreach ($ex as $key) { | |
$ref =& $ref[$key]; | |
} | |
$ref = $value; | |
unset($ref); | |
$values[$current] = array_replace_recursive($values[$current], $data[$current]); | |
return $buffer[$keys] = $value; | |
} else { | |
$values[$keys] = $value; | |
return $value; | |
} | |
} elseif (!empty($values[$keys])) { | |
return $values[$keys]; | |
} elseif (!empty($buffer[$keys])) { | |
return $buffer[$keys]; | |
} else { | |
$value = $values; | |
foreach (explode('.', $keys) as $key) { | |
if (!array_key_exists($key, $value)) { | |
return null; | |
} | |
$value = $value[$key]; | |
} | |
return $buffer[$keys] = $value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment