Page 1 of 1

GRRRRRRR Help me

Posted: Thu Feb 12, 2004 6:02 pm
by John Cartwright

Code: Select all

<?php
$maps =  array ('de_dust2' =>      array('$map','$record','$percent'), 
			   'de_aztec' =>       array('$map','$record','$percent'),
			   'de_nuke' =>        array('$map','$record','$percent'),  
			   'de_cpl_fire' =>    array('$map','$record','$percent'),  
			   'de_cpl_mill' =>    array('$map','$record','$percent'),
			   'de_inferno' =>     array('$map','$record','$percent'),  
			   'de_cbble' =>       array('$map','$record','$percent'),
			   'de_comrade' =>     array('$map','$record','$percent')); 
	   
$calcs =  array ('$de_dust2' =>     array('$de_dust2_a','$de_dust2_b','$de_dust2_c','$de_dust2_d'),
 
			     '$de_aztec' =>     array('$de_aztec_a','$de_aztec_b','$de_aztec_c','$de_aztec_d'),
			     '$de_nuke' =>      array('$de_nuke_a','$de_nuke_b','$de_nuke_c','$de_nuke_d'),
			     '$de_cpl_fire' =>  array('$de_cpl_fire_a','$de_cpl_fire_b','$de_cpl_fire_c','$de_cpl_fire_d'),
			     '$de_cpl_mill' =>  array('$de_cpl_mill_a','$de_cpl_mill_b','$de_cpl_mill_c','$de_cpl_mill_d'),
			     '$de_inferno' =>   array('$de_inferno_a','$de_inferno_b','$de_inferno_c','$de_inferno_d'),
			     '$de_cbble' =>     array('$de_cbble_a','$de_cbble_b','$de_cbble_c','$de_cbble_d'),
			     '$de_comrade' =>   array('$de_comrade_a','$de_comrade_b','$de_comrade_c','$de_comrade_d'));
		
			   foreach($de_aztec as $key => $value) $de_aztec[$key]=0; 			    
			   foreach($de_nuke as $key => $value) $de_nuke[$key]=0;
			   foreach($de_cpl_fire as $key => $value) $de_cpl_fire[$key]=0;
			   foreach($de_cpl_mill as $key => $value) $de_cpl_mill[$key]=0; 
			   foreach($de_inferno as $key => $value) $de_inferno[$key]=0;
			   foreach($de_cbble as $key => $value) $de_cbble[$key]=0;
			   foreach($de_comrade as $key => $value) $de_comrade[$key]=0; 
?>
All the foreach() are giving me errors that they are undefined :S This really isnt a good day for me :P plz help

Posted: Thu Feb 12, 2004 6:08 pm
by markl999
Lines like :
'de_nuke' => array('$map','$record','$percent'),
should be
'de_nuke' => array($map,$record,$percent),

foreach($de_aztec as $key => $value) $de_aztec[$key]=0;
^^not sure what this line is supposed to be doing, but looks like your foreach should be like :
foreach($maps as $key=>$val)

$key will be de_dust2, de_aztec etc.. and $val will be an array containing the $map, $record and $percent values respectively.

Posted: Thu Feb 12, 2004 6:18 pm
by John Cartwright
I'm a bit confused about the foreach thing, I don't understand where your getting at with it.

Posted: Thu Feb 12, 2004 6:21 pm
by markl999
Well, you have foreach($de_aztec as $key => $value) , and $de_aztec isn't an array, but, $maps['de_aztec'] is the array you need to access, so using foreach($maps as $key=>$val) will loop over all the maps.

What were you trying to acheive with foreach($de_aztec as $key => $value) $de_aztec[$key]=0; ? Explaining this might help us understand what the correct code should be, as i'm not sure what it should be doing :o

Posted: Thu Feb 12, 2004 6:23 pm
by John Cartwright
It is setting all the variables in the array to 0.....

I have another question though:

Code: Select all

<?php
$maps =  array ('de_dust2' =>      array($map,$record,$percent),  
			   'de_aztec' =>       array($map,$record,$percent), 
			   'de_nuke' =>        array($map,$record,$percent), 
			   'de_cpl_fire' =>    array($map,$record,$percent), 
			   'de_cpl_mill' =>    array($map,$record,$percent), 
			   'de_inferno' =>     array($map,$record,$percent), 
			   'de_cbble' =>       array($map,$record,$percent), 
			   'de_comrade' =>     array($map,$record,$percent)); 
	   
$calcs =  array ('$de_dust2' =>     array($de_dust2_a,$de_dust2_b,$de_dust2_c,$de_dust2_d),
				 '$de_aztec' =>     array($de_aztec_a,$de_aztec_b,$de_aztec_c,$de_aztec_d),
			     '$de_nuke' =>      array($de_nuke_a,$de_nuke_b,$de_nuke_c,$de_nuke_d),
			     '$de_cpl_fire' =>  array($de_cpl_fire_a,$de_cpl_fire_b,$de_cpl_fire_c,$de_cpl_fire_d),
			     '$de_cpl_mill' =>  array($de_cpl_mill_a,$de_cpl_mill_b,$de_cpl_mill_c,$de_cpl_mill_d),
			     '$de_inferno' =>   array($de_inferno_a,$de_inferno_b,$de_inferno_c,$de_inferno_d),
			     '$de_cbble' =>     array($de_cbble_a,$de_cbble_b,$de_cbble_c,$de_cbble_d),
			     '$de_comrade' =>   array($de_comrade_a,$de_comrade_b,$de_comrade_c,$de_comrade_d));
?>
Notice its $calcs = array ('$de_dust2' => and $maps= array ('$de_dust2' => ( for example )

How do I differenciate the 2 arrays apart in the foreach statements

Posted: Thu Feb 12, 2004 6:27 pm
by markl999
Why have 2 separate arrays?
Can't you merge them into one?
'de_dust2' => array($map,$record,$percent,$de_dust2_a,$de_dust2_b,$de_dust2_c,$de_dust2_d)

Posted: Thu Feb 12, 2004 6:37 pm
by John Cartwright
thats true rofl rofl rofl.. I'm so stupid hehe.

But back to the question at hand, how do I format it properly, I'm still getting the same error msg :(

Posted: Thu Feb 12, 2004 6:40 pm
by markl999
Might be better to repost the code you have now and the error you are getting as i'm a bit confused what you have now after these changes etc.. ;)

Posted: Thu Feb 12, 2004 6:42 pm
by John Cartwright

Code: Select all

<?php
$maps =  array ('de_dust2' =>    array($map,$record,$percent), 
			   'de_aztec' =>     array($map,$record,$percent),
			   'de_nuke' =>      array($map,$record,$percent),  
			   'de_cpl_fire' =>  array($map,$record,$percent),  
			   'de_cpl_mill' =>  array($map,$record,$percent),
			   'de_inferno' =>   array($map,$record,$percent),  
			   'de_cbble' =>     array($map,$record,$percent),
			   'de_comrade' =>   array($map,$record,$percent)); 
	   
			   foreach($de_aztec as $key => $value) $de_aztec[$key]=0; 			    
			   foreach($de_nuke as $key => $value) $de_nuke[$key]=0;
			   foreach($de_cpl_fire as $key => $value) $de_cpl_fire[$key]=0;
			   foreach($de_cpl_mill as $key => $value) $de_cpl_mill[$key]=0; 
			   foreach($de_inferno as $key => $value) $de_inferno[$key]=0;
			   foreach($de_cbble as $key => $value) $de_cbble[$key]=0;
			   foreach($de_comrade as $key => $value) $de_comrade[$key]=0; 
?>
I still havn't added the other variables to the array but I will.

The errors include

Warning: Invalid argument supplied for foreach() in ***********/records.php on line 44

Warning: Invalid argument supplied for foreach() ***********/records.php on line 45

Warning: Invalid argument supplied for foreach() ***********/records.php on line 46

Warning: Invalid argument supplied for foreach() ***********/records.php on line 47

Warning: Invalid argument supplied for foreach() ***********/records.php on line 48

Warning: Invalid argument supplied for foreach() ***********/records.php on line 49

Warning: Invalid argument supplied for foreach() ***********/records.php on line 50

Posted: Thu Feb 12, 2004 6:49 pm
by markl999
ok, it's back to foreach($de_aztec as $key => $value) $de_aztec[$key]=0;

$de_aztec isn't an array. Try this as a test to see what i mean:

Code: Select all

foreach($maps as $key=>$val){
    echo $key.'<br />';
    echo $val[0].' '.$val[1].'<br /><br />';
}
and see what that chucks out.

Posted: Thu Feb 12, 2004 6:55 pm
by John Cartwright
It outputted all the different maps

de_dust2


de_aztec


de_nuke


de_cpl_fire


de_cpl_mill


de_inferno


de_cbble


de_comrade

Posted: Thu Feb 12, 2004 7:00 pm
by John Cartwright
what I really need to know is how to set all the variables in each row to 0

Posted: Thu Feb 12, 2004 7:08 pm
by markl999

Code: Select all

foreach($maps as $key=>$val){
  $count = count($val);
  for($x=0;$x<$count;$x++){
    $maps[$key][$x] = 0;
  }
}
should do that. I'm convinced there's a whole simpler way of doing what you're trying to acheive, but my head hurts now and i've lost track of the big picture ;)