Last active
December 15, 2015 15:19
-
-
Save ScreamingDev/5281177 to your computer and use it in GitHub Desktop.
Exchange 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 | |
$default = [ | |
'one' => null, | |
'two' => null, | |
]; | |
$incoming = ['two' => 123, 'three' => 345]; | |
// only allow existing keys | |
$incoming = array_intersect_key($incoming, $default); | |
// fill up with defaults | |
$result = array_merge($default, $incoming); | |
// var_dump($result); | |
?> |
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 | |
public function exchangeArray($data) | |
{ | |
// defaults | |
$default = array( | |
'foo' => null, | |
); | |
// only allow existing keys | |
$data = array_intersect_key($data, $default); | |
// fill up with defaults | |
$data = array_merge($default, $data); | |
// $this->data = $data; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment