Working with arrays

Example #3 1-based index with array()

<?php
$firstquarter
= array(1 => 'January', 'February', 'March');
print_r($firstquarter);
?>

The above example will output:

Array

(

[1] => January

[2] => February

[3] => March

)

As in Perl, you can access a value from the array inside double quotes.

However, with PHP you’ll need to enclose your array between curly braces.

Example #4 Accessing an array inside double quotes

<?php$foo = array('bar' => 'baz');

echo "Hello {$foo['bar']}!"; // Hello baz!

?>

I got this info at php.net

Leave a Reply