array_sum() argument not an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

array_sum() argument not an array

Post by Bill H »

I have the array in an include file,

Code: Select all

     $Qcnt = array(1=>array(1=>array(4,4,1,2,4),2=>array(4,4,1,2,4),3=>array(6,3,1,5,4),4=>array(3,3,1,5,4)),           // number of questions
                   2=>array(1=>array(4,4,1,2,4),2=>array(4,4,1,2,4),3=>array(6,3,1,5,4),4=>array(3,3,1,5,4)));          // in each segment

     $CurrVer = 1;                      // applies to shopper creation and blank forms
in a file using that is the following,

Code: Select all

if (isset($_POST['Basic']))                   // updating at basic level, moving on or not (status is zero)
{                                                  // $_POST['Basic'] is the report type (1-4)
     $Typ = array_sum($Qcnt[$CurrVer][$_POST['Basic']]);         // some have more questions than others
and I get the error "The argument should be an array" for the "$Typ=" line.
Echoing the vars says that $_POST['Basic'] = 2 and $CurrVer = 1
Why is the argument not an array?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: array_sum() argument not an array

Post by John Cartwright »

What does

Code: Select all

var_export($Qcnt[$CurrVer][$_POST['Basic']]);


say?
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: array_sum() argument not an array

Post by Bill H »

Well, this is getting wierd,

Code: Select all

array ( 0 => 4, 1 => 4, 2 => 1, 3 => 2, 4 => 4, )
I'm going to kill this client. I swear, I'm going to kill her. Dead.

I decided to go try the function in question and, guess what, I don't get the error. It may be that her browser was caching the include file, I don't know, but I don't get the furshlugginer error. It processes the form precisely as it is supposed to do, using all four browsers that I test with.

I'll tell her to clear cache, reboot her damn computer if need be, and try again.

Sorry.
Post Reply