Last active
December 16, 2015 14:09
-
-
Save benklocek/5446492 to your computer and use it in GitHub Desktop.
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 | |
//Goal to merge $user['CustomFields'] with $customfields. | |
//fields from API | |
$customfields[] = (object) array('Key' => 'Email Lists', 'Value' => 'Events'); | |
$customfields[] = (object) array('Key' => 'Office Affiliation', 'Value' => 'Oxford'); | |
$customfields[] = (object) array('Key' => 'Office Affiliation', 'Value' => 'San Francisco'); | |
//fields from form | |
$user['CustomFields'][] = array('Key' => 'Email Lists', 'Value' => 'Newsletter'); | |
$user['CustomFields'][] = array('Key' => 'Email Lists', 'Value' => 'Events'); | |
$user['CustomFields'][] = array('Key' => 'Office Affiliation', 'Value' => 'Oxford'); | |
echo '<pre>'; | |
print_r($customfields); | |
print_r($user['CustomFields']); | |
echo '</pre>'; | |
foreach( $customfields as $customfield ){ | |
//echo $customfield->Value .'<br>'; | |
//find matches in array | |
if(!in_array_recursive($customfield, $user['CustomFields'])) | |
$user['CustomFields'][] = array('Key' => $customfield->Key, 'Value' => $customfield->Value); | |
} | |
echo '<pre>Updated Version | |
'; | |
print_r($user['CustomFields']); | |
echo '</pre>'; | |
function in_array_recursive($needle, $haystack) { | |
foreach ($haystack as $element) { | |
if ((object) $element == (object) $needle) return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment