Forum Moderators: coopster

Message Too Old, No Replies

Arrays, can someone explain these?

         

AffiliateDreamer

4:56 pm on Dec 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

Can someone explain what is going on here?

$_TEST = array();

$_TEST['HELLO']['FLOOR1'] = array(
'a' => 1,
'b' => 2,
'c' => 4,
'd' => 8

);

$_TEST['HELLO']['FLOOR1'] = array(
'a' => 1,
'b' => 2
);

I'm looking at this code, and there doesn't seem to be any definition for 'hello' and 'floor1' and 'floor2'.

Does PHP just dynamically you to name array indexes like this? And what about the data type?

jatar_k

5:01 pm on Dec 28, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> Does PHP just dynamically you to name array indexes like this?

yes

>> And what about the data type?

types are fluid, the variable will be typed based on what you store in it or how you create it. You can retype on the fly as well, though this does sometimes allow for error if you don't pay close attention.

eelixduppy

5:27 pm on Dec 28, 2007 (gmt 0)



>> I'm looking at this code, and there doesn't seem to be any definition for 'hello' and 'floor1' and 'floor2'.

The indices are case-sensitive and therefore would be 'HELLO', 'FLOOR1' and 'FLOOR2', respectively. I believe you also have a misspelling as you don't actually have a 'FLOOR2' index. Try the following:


$_TEST = array();
#
$_TEST['HELLO']['FLOOR1'] = array(
'a' => 1,
'b' => 2,
'c' => 4,
'd' => 8
);
#
$_TEST['HELLO']['FLOOR2'] = array(
'a' => 1,
'b' => 2
);
echo '<pre>';
[url=http://www.php.net/print-r]print_r[/url]($_TEST); #print the array out
echo '</pre>';

Here's more information on arrays for your reading pleasure :)
[php.net...]