I am trying to come up with a function in order to get me some specific data from an array. It's part of a permissions system I am doing for a page.
Here is the array of data I have:
[views] => Array
(
[0] => SimpleXMLElement Object
(
[permItem] => viewOriginalFeedback
[actions] => SimpleXMLElement Object
(
[view] => 0
[edit] => 0
)
)
[1] => SimpleXMLElement Object
(
[permItem] => viewTarget
[actions] => SimpleXMLElement Object
(
[view] => 0
[edit] => 0
)
)
)
)
What I am trying to do is create a function where I can pass is pass it a perm item and action like so. if(myFunction('viewOriginalFeedback', 'view')) if this returns 1 I show the content, if its a 0 then I know to not show it.
The issue is that these views may not exist at all in the array so in that case it would be false as if the action was set to 0.
I was playing around with something like this but I feel like there is a more elegant way to complete it.
// Permission Check
function checkPerm($permItem, $action){
foreach($permissions->data->views as $view){
if($view->permItem == $permItem){
if($view->actions == $action){
return $view->actions->$action;
}
}
}
}
if(isset($view->actions->$action))and I would probably go for an associative array instead of array of objects.