GRRRRRRR Help me

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
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

GRRRRRRR Help me

Post 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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I'm a bit confused about the foreach thing, I don't understand where your getting at with it.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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 :(
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.. ;)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

what I really need to know is how to set all the variables in each row to 0
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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 ;)
Post Reply