You cannot use a scalar value as an array

I am trying to use this code:

$rescntryvals[] = $rescntry; $rescntry = ""; $resclkvalscntry[] = $rclick; $rclick = ""; $resclkaddsnm[] = $addsnmame; $addsnmame = ""; 

But I get this:

warning: you cannot use a scalar value as an array

Why? And what is the solution?

+8
php
source share
4 answers

You must declare $rescntryvals as an array before. By default, all variables are of type null (undefined) until you define them.

 $rescntryvals = array(); $rescntryvals[]=$rescntry; 
+8
source share

Try the following:

Declare Variables

 $rescntryvals = array(); $rescntryvals[]=$rescntry; 

OR

 $rescntryvals = array($rescntry); 

Link: http://php.net/manual/en/language.types.array.php

+5
source share

on the first line, define the variables that should be an array.

 $rescntryvals = array(); $resclkvalscntry = array(); $resclkaddsnm = array(); 
+2
source share

Also, I got this error because I used the sort functions incorrectly.

After installing my associative arrays, I would try to return a sorted array as follows:

 $arr = array(...); $arr = asort($arr); //print_r($arr); -> 1 

Of course, this only returns the boolean true that has been sorted by the array.

The correct procedure:

 $arr = array(...); asort($arr); //print_r($arr); -> sorted array 
0
source share

All Articles