PHP syntax for arrays: different behaviour between PHP versions

前端 未结 1 711
感动是毒
感动是毒 2020-12-12 01:13

I made a PHP page with an array using the following syntax:

$Legenda = [
    \"Cores\"      => [\"#FF0000\", \"#FFA500\", \"#FFFF00\", \"#64FF00\", \"#00A         


        
相关标签:
1条回答
  • 2020-12-12 01:58

    The shortened array syntax was only added in PHP 5.4: Arrays

    As of PHP 5.4 you can also use the short array syntax, which replaces array() with [].

    <?php
    $array = array(
        "foo" => "bar",
        "bar" => "foo",
    );
    
    // as of PHP 5.4
    $array = [
        "foo" => "bar",
        "bar" => "foo",
    ];
    ?>
    

    Live result

    0 讨论(0)
提交回复
热议问题