skahan
8/21/2013 - 11:39 PM

PHP Arrays Basics

PHP Arrays Basics

<?php

# You can make an array using old sytax:

$chunked_tix_array = array(array('ABVRX','ABVYX','ABWAX'),array('ACAHX','ACAJX','ACAPX'));
print_r($chunked_tix_array);
Array
(
    [0] => Array
        (
            [0] => ABVRX
            [1] => ABVYX
            [2] => ABWAX
        )
    [1] => Array
        (
            [0] => ACAHX
            [1] => ACAJX
            [2] => ACAPX
        )
)

# Or new syntax:

$chunked_tix_array_new_format = [['ABVRX','ABVYX','ABWAX'],['ACAHX','ACAJX','ACAPX']];
print_r($chunked_tix_array_new_format);
Array
(
    [0] => Array
        (
            [0] => ABVRX
            [1] => ABVYX
            [2] => ABWAX
        )
    [1] => Array
        (
            [0] => ACAHX
            [1] => ACAJX
            [2] => ACAPX
        )
)
<?php
//To assign associative array key-value pairs, use the => (equal sign+greater than sign) sytnax:
$assoc = ['api_code'=>'xxx','array_date'=>'1969-10-15'];

//To access a associative array value:
echo $assoc["api_code"];//Burt

//To assign value to existing array:
$assoc["api_code"] = "Debbie";
echo $assoc["api_codee"];//Debbie

//You can't refer to associative array value by number (unless of course you indexed an array object with a number):
echo $assoc[0];//Undefined Offset Error
?>