Welcome Guest, Not a member yet? Register   Sign In
General PHP load question!
#1

[eluser]Lazos[/eluser]
I have this LOOP in my script. I was wondering if that will make the website really slow or PHP/Apache will handle them without a problem. Let's say for example this loop it will execute 30 times every time I visit the particular page.

What do you think?

Code:
function deleteContent ($array) {
        if (array_key_exists('Remove Pages', $this->groupperms) && (array_key_exists('Modify Any Page', $this->groupperms)) && (!$this->CI->contentmodel->hasChild($array['content_id'])) && (!$this->CI->contentmodel->getOwnership($array['content_id'], $this->userid))) {
            return '<a href="deletecontent.php?content_id='.$array['content_id'].'">'.$this->CI->admin_theme->displayImage('images/admin/icons/system/delete.gif', $this->CI->lang->line('delete'), '', '','systemicon').'</a>';
        } else
        {
            if (!array_key_exists('Remove Pages', $this->groupperms) && (!array_key_exists('Modify Any Page', $this->groupperms)) && (!$this->CI->contentmodel->hasChild($array['content_id'])) && (!$this->CI->contentmodel->getOwnership($array['content_id'], $this->userid))) {
            return '<a href="deletecontent.php?content_id='.$array['content_id'].'">'.$this->CI->admin_theme->displayImage('images/admin/icons/system/delete.gif', $this->CI->lang->line('delete'), '', '','systemicon').'</a>';
            } else
            {
                if (!array_key_exists('Remove Pages', $this->groupperms) && (!array_key_exists('Modify Any Page', $this->groupperms)) && ($this->CI->contentmodel->hasChild($array['content_id'])) && (!$this->CI->contentmodel->getOwnership($array['content_id'], $this->userid))) {
                return '<a href="deletecontent.php?content_id='.$array['content_id'].'">'.$this->CI->admin_theme->displayImage('images/admin/icons/system/delete.gif', $this->CI->lang->line('delete'), '', '','systemicon').'</a>';
                } else
                {
                    if (array_key_exists('Remove Pages', $this->groupperms) && (array_key_exists('Modify Any Page', $this->groupperms)) && ($this->CI->contentmodel->hasChild($array['content_id']))) {
            return '<a href="deletecontent.php?content_id='.$array['content_id'].'">'.$this->CI->admin_theme->displayImage('images/admin/icons/system/delete.gif', $this->CI->lang->line('delete'), '', '','systemicon').'</a>';
                    }
                }
            }
        }
    }
#2

[eluser]m4rw3r[/eluser]
Try to split the ifConfused like this and then replace array_key_exists($key, $array) with isset($array[$key]):
Code:
if(isset($this->groupperms['Remove Page']))
{
    if(isset($this->groupperms['Modify Any Page']))
    {
    
    }
    else
    {
    
    }
}
else
{
    
}
This will make it a bit faster, but most importantly, it will be easier to read and maintain.




Theme © iAndrew 2016 - Forum software by © MyBB