September 12, 2013

PHP Notice: Array to string conversion Error

Beardy’s Question:

Been experiencing this error for a little while and can’t find any conclusive answers on fixing it. I have tried removing quotes from $key in line 59 but to no avail.

if (!get_magic_quotes_gpc()) {
    if (isset($_POST)) {
        foreach ($_POST as $key => $value) {
            $_POST['$key'] =  trim(addslashes($value));
        }
    }

    if (isset($_GET)) {
        foreach ($_GET as $key => $value) {
            $_GET[$key] = trim(addslashes($value));
        }
    }   
}

LINE 59

$_POST['$key'] =  trim(addslashes($value));

Error On Screen

Notice: Array to string conversion in
C:Inetpubvhostsdomain.comhttpdocslibraryconfig.php on
line 59

Check if it is array before you assign it

$_POST[$key] =  !is_array($value) ? trim(addslashes($value)) : '';
   //  ^   Remove the quotes here                          //  ^ Do something 
                                                           //  Instead of 
                                                           //  Using empty

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!