Thursday, August 20, 2009

More Array Stuff

Using the code in my previous post, I disabled the existing echos and tried this:


The output was

As expected, so I can access the array I need based on the $selected_array var.

PHP mixed arrays

I wanted to verify that I could mix scalar data and array data in the same array. Here's what I came up with.


echo ("first is {$test_array['first']}
echo ("second is {$test_array['second']}
echo ("array1 begin is {$test_array['array1']['begin']}
echo ("array1 middle is {$test_array['array1']['middle']}
echo ("array1 end is {$test_array['array1']['end']}
foreach ($test_array['array2'] as $value){
echo("array2 key $count is $value

The output was:
first is 1
second is 2
array1 begin is one
array1 middle is 2
array1 end is three
array2 key 0 is a
array2 key 1 is b
array2 key 2 is c

This means we can use mixed data in one array and access the scalar and composite data as expected.