Created
July 3, 2014 20:14
-
-
Save endel/6da6709412e679c32295 to your computer and use it in GitHub Desktop.
PHP: remove and return key from array
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 | |
$name = $attribute['name']; | |
unset($attribute['name']); | |
$type = camel_case($attribute['type']); | |
unset($attribute['type']); | |
$index = null; | |
if (isset($attribute['index'])) { | |
$index = $attribute['index']; | |
unset($attribute['index']); | |
} | |
$default = null; | |
if (isset($attribute['default'])) { | |
$default = $attribute['default']; | |
unset($attribute['default']); | |
} |
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 array_remove(array &$arr, $key) { | |
if (array_key_exists($key, $arr)) { | |
$val = $arr[$key]; | |
unset($arr[$key]); | |
return $val; | |
} | |
return null; | |
} | |
$name = array_remove($attribute, 'name'); | |
$type = camel_case(array_remove($attribute, 'type')); | |
$index = array_remove($attribute, 'index'); | |
$default = array_remove($attribute, 'default'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment