Problem accessing an array inside if/switch
| From: | Ben Ramsey | Date: | Mon, 29 Mar 2004 16:36:56 +0000 |
| Subject: | Problem accessing an array inside if/switch | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-181676@lists.php.net to get a copy of this message | ||
One of my co-workers posted this to PHPBuilder, and I'm posting it here. It's a problem that's baffling the snot out of us. It's an array that you can print_r() from outside an if or switch/case statement, but from inside, it seems unaccessible. His post follows:
<quote>
Ok Background:
Database: MS SQL
PHP: PHP 5 RC1
$block_data is pulled from the database and stored earlier on. The datatype of ranges is int.
$events is a multi-dimensional array also pulled from the database.
Problem:
Whenever I try to print the varible $events inside an ( if ) statement or a ( case ) statement it appers to be blank, or inaccessible.
<code>
$myBlock = $block_data[0]["ranges"];
//$myBlock= 6; // Un-comment this and the print_r($events) inside the if statement prints out correctly. //$myArray = array(1, 2, 3, 4, 5); //Change the print_r($events) inside to $myArray and uncomment this and it works fine.
print_r($events); // This prints out fine.if ($myBlock == 6) {
echo $block_data[0]["ranges"]."<br>"; // This has a value of 6
print_r($events); // This prints out Array()
}
print_r($events); // This prints out fine.</code> As you see it appears that the problem lies some how with two varibles that are pulled from the database. However, it should not make a difference as they are both correctly set before AND after the if statement. Any ideas on this i'm lost. Jesse </quote> -- Regards, Ben Ramsey http://benramsey.com http://www.phpcommunity.org/wiki/People/BenRamsey