Jump to content

Arrays Not Working


Guest FirefoxRocks
 Share

Recommended Posts

Guest FirefoxRocks

This must be a really dumb error but I'm not sure why I can't access my arrays:

<?php	session_start();	header("Content-Type: text/html;charset=utf-8");	header("Content-Language: en-CA");	ob_start("ob_gzhandler");	date_default_timezone_set("America/Rainy_River");?><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html lang="en-CA"><head>	<title>Update</title></head><body>  	<div id="ac-body">		<div id="ac-content">					<h2>Update</h2>			<?php								for((int)$i=0; $i<4; ++$i) {					$team = $_POST["team"][$i];					echo $team["name"];				}			?>		</div>	</div>	</body></html>

This is what my POST array looks like:

Array( [team] => Array ( [0] => Array ( ["name"] => Team A ["points"] => 280 ) [1] => Array ( ["name"] => Team B ["points"] => 70 ) [2] => Array ( ["name"] => Team C ["points"] => 10 ) [3] => Array ( ["name"] => Team D ["points"] => 0 ) ) [player] => Array ( [0] => Array ( ["name"] => Player 1 ["team"] => Team A ["goals"] => 0 ["assists"] => 0 ) [1] => Array ( ["name"] => Player 2 ["team"] => Team C ["goals"] => 5 ["assists"] => 3 ) ))
What is the error I am making?
Link to comment
Share on other sites

Guest FirefoxRocks

Well originally it should do other stuff but I stripped it all out because I couldn't get this array thing working, right now it should just print out the names.

Link to comment
Share on other sites

Guest FirefoxRocks

Well it's not, even though the print_r output is the one I posted above. I also checked the HTTP and well obviously the page is receiving the data because I can use print_r to output it.

Link to comment
Share on other sites

Then there's something wrong with $_POST['team']. When I run this:

<?php$ar = array(  array('name' => 'aaa', 'num' => 10),  array('name' => 'bbb', 'num' => 20),  array('name' => 'ccc', 'num' => 30));print_r($ar);?>

I get this:

Array(	[0] => Array		(			[name] => aaa			[num] => 10		)	[1] => Array		(			[name] => bbb			[num] => 20		)	[2] => Array		(			[name] => ccc			[num] => 30		))

Note how the names do not have quotes around them. The names in your print_r output do have quotes, which tells me that the quotes are part of the name. e.g.:$_POST['team'][0]['"name"']

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...