Having a hard time figuring out how to explain it, so maybe the code will help.
$out = array();
source_addValue($out['sources']['site1']['user_id'], '12345');
source_addValue($out['sources']['site1']['username'], 'testuser');
source_addValue($out['sources']['site1']['address']['state'], 'CA');
function source_addValue($field, $value) {
global $out;
if (!$field) $field = $value;
}
That, or since the $out['sources']
part remain the same, maybe something like:
$out = array();
source_addValue('site1', 'user_id', '12345');
source_addValue('site1', 'username', 'testuser');
source_addValue('site1', array('address','state'), 'CA');
function source_addValue($site, $field, $value) {
global $out;
if (!$out['sources'][$site]$field) $out['sources'][$site]$field = $value;
}
Either way, I'm getting hung up on the function, and specifically the if
statement. I just need to be able to check to see if that array value has been set for $out
(with the ability to check sub-arrays) and if it isn't, add it to the $out
array.