Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2012
    Location
    United Kingdom
    Posts
    39
    Thanks
    3
    Thanked 1 Time in 1 Post

    array_merge() argument #2 not array, when it is.

    Hi,
    I've built a language system for my CMS & when i try to set more than one case it says argument #2 not array, when i know it is.

    Language Class:
    PHP Code:
    class Language
    {
        public 
    $loc = array();
        
        public function 
    Add($keys)
        {
            if(
    is_array($keys))
            {
                foreach(
    $keys as $key)
                {
                    require_once 
    LANG_DIR "English.php";
                    
    $this->loc array_merge($this->loc$loc);
                }
            }
            else
            {
                
    $key $keys;
                require_once 
    LANG_DIR "English.php";
                
    $this->loc array_merge($this->loc$loc);
            }
        }
        
        public function 
    Dump()
        {
            unset(
    $this->loc);
        }

    English.php file:
    PHP Code:
    switch($key)
    {
        case 
    "housekeeping.menu.staff":
            
    $loc['menu.staff.title'] = "Staff";
            
    $loc['menu.staff.home'] = "Home";
            
    $loc['menu.staff.rules'] = "Rules";
            
    $loc['menu.staff.logout'] = "Logout";
        break;
        
        case 
    "housekeeping.menu.news":
            
    $loc['menu.news.title'] = "News";
        break;

    While doing a while() query i'm getting argument #2 not array.
    Example:
    PHP Code:
    while($stmt->fetch())
    {
        
    $lang->Add("housekeeing.menu." $lang_cat);

    It's just an example, the point i'm trying to get across is argument #2 is array.
    If i do $lang->Add("housekeeing.menu." . $lang_cat); once it's fine, but when add more cats i get the arguments #2 not array.
    I don't understand the problem.

    The actual functions im using this in:
    PHP Code:
    public function BuildMenu($url)
    {
        
    $stmt $this->db->stmt_init();
        
    $return "";
        
        if(
    $stmt->prepare("SELECT id, language_set, language_get FROM pegg_cms_hk_menu WHERE parent_id = 0 AND minrank <= ? ORDER BY order_id + 0"))
        {
            
    $stmt->bind_param("i"$this->server->site->GetDataByUsername($_SESSION['PEGG']['HK']['USERNAME'], "rank"));
            
    $stmt->bind_result($id$lang_set$lang_get);
            
    $stmt->execute();
            
    $stmt->store_result();
            
            while(
    $stmt->fetch())
            {
                
    $this->lang->Add("housekeeping.menu." $lang_set);
                
                
    $return .= "<div class=\"box-container\">";
                
    $return .= "<div class=\"head-container\">" $this->lang->loc['menu.' $lang_set "." $lang_get] . "</div>";
                
    $return .= "<div class=\"menuitems-container\">";
                
    $return .= $this->BuildSubMenu($id$url);
                
    $return .= "</div>";
                
    $return .= "</div>";
            }
            
            
    $stmt->close();
        }
        else
        {
            
    LogError($this->db->error"mysqli");
            
    TriggerError("MySQLi Error"$this->db->error);
        }
        
        return 
    $return;
    }

    public function 
    BuildSubMenu($parent$url)
    {
        
    $stmt $this->db->stmt_init();
        
    $return "";
        
        if(
    $stmt->prepare("SELECT language_set, language_get, url, resource FROM pegg_cms_hk_menu WHERE parent_id = ? AND minrank <= ? ORDER BY order_id + 0"))
        {
            
    $stmt->bind_param("ii"$parent$this->server->site->GetDataByUsername($_SESSION['PEGG']['HK']['USERNAME'], "rank"));
            
    $stmt->bind_result($lang_set$lang_get$url2$resource);
            
    $stmt->execute();
            
    $i "a";
            
            while(
    $stmt->fetch())
            {
                if(
    $url == $url2)
                {
                    
    $return .= "<div class=\"" $i " selected-link\">";
                    
    $return .= $this->lang->loc['menu.' $lang_set "." $lang_get];
                    
    $return .= "</div>";
                }
                else
                {
                    
    $return .= "<a href=\"" $this->config->settings->housekeeping->path "/index.php?url=" $url2 "\" class=\"" $i "\">";
                    
    $return .= $this->lang->loc['menu.' $lang_set "." $lang_get];
                    
    $return .= "</a>";
                }
                
                
    $i++;
                if(
    $i == "c")
                {
                    
    $i "a";
                }
            }
            
            
    $stmt->close();
        }
        else
        {
            
    LogError($this->db->error"mysqli");
            
    TriggerError("MySQLi Error"$this->db->error);
        }
        
        return 
    $return;

    It sets the first part of the menu locale, but then i get argument #2 not array when it does more than 1 adding.

    Thanks.
    Last edited by Clawed; 06-13-2013 at 11:36 PM.

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,215
    Thanks
    12
    Thanked 338 Times in 334 Posts
    it’s a scope problem, cf. include():
    When a file is included, the code it contains inherits the variable scope of the line on which the include occurs. Any variables available at that line in the calling file will be available within the called file, from that point forward. However, all functions and classes defined in the included file have the global scope.
    though you can easily test that with var_dump().
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    New Coder
    Join Date
    Nov 2012
    Location
    United Kingdom
    Posts
    39
    Thanks
    3
    Thanked 1 Time in 1 Post
    Yea my problem was require_once in Add() function, now i changed it to require it works


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •