Array not the same in included file

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
Heggi
Forum Newbie
Posts: 2
Joined: Wed Dec 16, 2009 3:26 am

Array not the same in included file

Post by Heggi »

Hello guys,
I'm new here and i recently started php programming and i've come across a problem that i can't seem to solve.
Please help me. I dont know why this error occurs...

i have a file called stats.php were i have a 2D array with a lot of values in.
i get the values from the array by using the key (string)
like this, i.e. $value = $stats["a"]["b"];

further down i have included another file: file2.php.

when im in file2.php some of the array values aren't there anymore...
$stats["a"]["b"] may not have a value in file2.php
why?

so if i make a funtion that returns the stats from file2.php to stats.php
and compares them they are not similar.

stats.php looks something like this:

include('file2.php');
$stats2 = getstats(); //function that returns $stats from file2.php

if($stats["a"]["b"] != $stats2["a"]["b"])
echo "<br/>WHY DOES THIS HAPPEN???<br/>";

hope it makes sense to u...
thx for the help.
Heggi
Forum Newbie
Posts: 2
Joined: Wed Dec 16, 2009 3:26 am

Re: Array not the same in included file

Post by Heggi »

Ok it works now!?

all i did was to change to another array and use indexes instead of string keys

i did this in stats.php...
$values[1][1] = $stats["a"]["b"];

and used $values array in file2.php instead.

how come this works but not what i had before?

Have you come across something similar? explanation?
Post Reply