Home
Manage Your Code
Snippet: Array Differencing in PHP 5.4 (PHP)
Title: Array Differencing in PHP 5.4 Language: PHP
Description: Array enhancements from PHP 5.4 compared to PHP 5.3. Views: 305
Author: Nathan Daly Date Added: 6/24/2012
Copy Code  
<?php
/**
 * Array Differencing in PHP 5.4
 * Author: Nathan
 * Date: 24/06/12
 */

/* PHP 5.4 method []
*Square brackets can be used in place of parentheses
*/
function getArray54()
{

       return [
           'key' => 'value',
           'another' => 'another_value',
           'number' => array(1 ,2 ,3 ,4)
        ];

}

//Call new method
var_dump(getArray54() ['numbers']);


/* PHP 5.3 method {}
*Older method with parentheses and array keyword
*/
function getArray53()
{

    return array(
        'key' => 'value',
        'another' => 'another_value',
        'number' => array(1 ,2 ,3 ,4)
    );

}

//Call to older method
var_dump(getArray253());
Usage
Quicker ways to define array values.
Notes
Full video tutorial here: http://tutsplus.com/lesson/array-enhancements/