I've got some PHP which I'm sure could be done a little more elegantly. It functionally works, so it's more just for self learning.
I have an array (or object) with different alphabetic keys, and I'm looking to find out if a key is set, and if so, to return the remaining match.
The PHP code I have at the moment is just a basic if statement:
if(isset($item->revision->application_uid)) $item->type = 'application';
elseif(isset($item->revision->channel_uid)) $item->type = 'channel';
elseif(isset($item->revision->workout_uid)) $item->type = 'workout';
So essentially, I'm wanting to search all of the keys, and return the remaining part of the '_uid' key.
[EDIT] Further to this, I've come up with an alternative suggestion, however I'm still wondering if there's a better/more efficient way to do this.
foreach(array_keys((array) $item->revision) as $key)
{
if($match = strstr($key, '_uid', TRUE))
{
$item->type = $match;
break;
}
}
Thanks in advance.