Notice Array to string conversion in sugar charts

987 views Asked by At

How do I fix this error?

Notice: Array to string conversion in C:\xampp\htdocs\sugarcrm\include\SugarCharts\SugarChart.php on line 798

global $app_list_strings;
    $sortby1[] = array();
    foreach ($data_set as $row) {
        $sortby1[]  = $row[$keycolname1];
    }
    $sortby1 = array_unique($sortby1); <== line 798

I'm not familiar at all when it comes to php. Hope you can help me.

1

There are 1 answers

9
Death-is-the-real-truth On BEST ANSWER

Try this:-

global $app_list_strings;
    $sortby1 = array(); // define an array variable. The [] syntax is used for appending data to an array not for creating an array type variable.
    foreach ($data_set as $row) {
        $sortby1[]  = $row[$keycolname1]; // assign value to array variable
    }
    $sortby1 = array_unique($sortby1); // remove duplicate values.

Note:- check yourself that $app_list_strings and $data_set will be correctly defined and have values. Thanks.

$sortby1[] = array(); adds an array as the first element of the array $sortby1, means your array starts like this:Array ( [0] => Array() ...) and since array_unique() treats all values as strings, it's trying to convert the first element, which is an array as string, which then throws this notice.