I have an array ($entry
) that could have either of two sets of keys:
"custom_0_first" AND "custom_0_last";
OR
"custom_1_first" AND "custom_1_last";
I'm trying to do the following, but it doesn't seem to be setting the variables:
$firstname = array_search('custom_0_first', $entry) || array_search('custom_1_first', $entry);
$lastname = array_search('custom_0_last', $entry) || array_search('custom_1_last', $entry);
Note that $entry['custom_0_first']
does work fine. I was trying to avoid an IF statement here.
Is my understanding of how array_search or PHP
works incorrect? As I understand it, if the first array_search
doesn't find the key, the function returns FALSE
and then it will check the right side of the OR
statement. Is this incorrect? I saw array_intersect
that I thought might work, but it looks like that doesn't work with arrays with associative keys.
Aucun commentaire:
Enregistrer un commentaire