[PHP] Array assistance

2004-07-27 Thread Alex Hogan
Hi All,
 
I have a page where I'm collecting answers from a series of questions.
The questions are entered into the array one at a time so I can keep
track of paging.
$arans  =   array($_POST);
$_SESSION['arans'][$pageid] = $arans;

Then I want to check the sum of the array for scoring purposes. However
I have to get to the key that has the values for the scores.

for($i = 1; $i = 10; $i++){
print_r($_SESSION['arans'][$i]);
printbr;
}

Give me this...
 
Array ( [0] = Array ( [mc] = 0 [Submit] = Submit ) ) 
Array ( [0] = Array ( [mc] = 10 [Submit] = Submit ) ) 
Array ( [0] = Array ( [mc] = 0 [Submit] = Submit ) ) 
Array ( [0] = Array ( [truefalse] = 10 [Submit] = Submit ) ) 
Array ( [0] = Array ( [mc] = 0 [Submit] = Submit ) ) 
Array ( [0] = Array ( [truefalse] = 10 [Submit] = Submit ) ) 
Array ( [0] = Array ( [mc] = 0 [Submit] = Submit ) ) 
Array ( [0] = Array ( [truefalse] = 10 [Submit] = Submit ) ) 
Array ( [0] = Array ( [mc] = 10 [Submit] = Submit ) ) 
Array ( [0] = Array ( [truefalse] = 10 [Submit] = Submit ) )

Ten separate arrays with an array at 0 that has the data I'm after.
This is where I'm getting stuck.  How can I get to the keys that are
either 'mc' or 'truefalse' and sum them?

Thanks,

alex hogan

 

*
The contents of this e-mail and any files transmitted with it are confidential and 
intended solely for the use of the individual or entity to whom it is addressed. The 
views stated herein do not necessarily represent the view of the company. If you are 
not the intended recipient of this e-mail you may not copy, forward, disclose, or 
otherwise use it or any part of it in any form whatsoever. If you have received this 
e-mail in error please e-mail the sender. 
*

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array assistance

2004-07-27 Thread Jason Davidson
I would simply build the array more specifically, so that it doesnt
include things you dont want.
Jason

On Tue, 27 Jul 2004 16:20:02 -0500, Alex Hogan
[EMAIL PROTECTED] wrote:
 Hi All,
 
 I have a page where I'm collecting answers from a series of questions.
 The questions are entered into the array one at a time so I can keep
 track of paging.
 $arans  =   array($_POST);
 $_SESSION['arans'][$pageid] = $arans;
 
 Then I want to check the sum of the array for scoring purposes. However
 I have to get to the key that has the values for the scores.
 
 for($i = 1; $i = 10; $i++){
 print_r($_SESSION['arans'][$i]);
 printbr;
 }
 
 Give me this...
 
 Array ( [0] = Array ( [mc] = 0 [Submit] = Submit ) )
 Array ( [0] = Array ( [mc] = 10 [Submit] = Submit ) )
 Array ( [0] = Array ( [mc] = 0 [Submit] = Submit ) )
 Array ( [0] = Array ( [truefalse] = 10 [Submit] = Submit ) )
 Array ( [0] = Array ( [mc] = 0 [Submit] = Submit ) )
 Array ( [0] = Array ( [truefalse] = 10 [Submit] = Submit ) )
 Array ( [0] = Array ( [mc] = 0 [Submit] = Submit ) )
 Array ( [0] = Array ( [truefalse] = 10 [Submit] = Submit ) )
 Array ( [0] = Array ( [mc] = 10 [Submit] = Submit ) )
 Array ( [0] = Array ( [truefalse] = 10 [Submit] = Submit ) )
 
 Ten separate arrays with an array at 0 that has the data I'm after.
 This is where I'm getting stuck.  How can I get to the keys that are
 either 'mc' or 'truefalse' and sum them?
 
 Thanks,
 
 alex hogan
 
 *
 The contents of this e-mail and any files transmitted with it are confidential and
 intended solely for the use of the individual or entity to whom it is addressed. The
 views stated herein do not necessarily represent the view of the company. If you are
 not the intended recipient of this e-mail you may not copy, forward, disclose, or
 otherwise use it or any part of it in any form whatsoever. If you have received this
 e-mail in error please e-mail the sender.
 *
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Array assistance

2004-07-27 Thread Matt M.
 Ten separate arrays with an array at 0 that has the data I'm after.
 This is where I'm getting stuck.  How can I get to the keys that are
 either 'mc' or 'truefalse' and sum them?

foreach my man
http://us2.php.net/foreach

foreach ($_SESSION['arans'] as $arans) {
$truefalse += $arans['truefalse'];
$mc += $arans['mc'];
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php