note 117137 added to function.array

From: Date: Mon, 20 Apr 2015 21:13:56 +0000
Subject: note 117137 added to function.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-202306@lists.php.net to get a copy of this message
During initialization php parses every value as expression. One can declare variables, do calculations, or even manipulate "current" array <?php $arr['A'] = [ &$arr, // circular reference 'key' => 'val', $arr['B'] = [ // declare array, insert key and then value 'a' => 'b', ], ucfirst(strtolower('SOME TEXT')), true ? 'TRUE' : 'FALSE', // evaluate expression $x = 3, // declare variable $x *= 3, // perform calculations ]; var_dump($arr); // Output /* array(2) { 'B' => array(1) { 'a' => string(1) "b" } 'A' => array(7) { [0] => array(2) { 'B' => array(1) { ... } 'A' => &array } 'key' => string(3) "val" [1] => array(1) { 'a' => string(1) "b" } [2] => string(9) "Some text" [3] => string(4) "TRUE" [4] => int(3) [5] => int(9) } } */ ?> ---- Server IP: 72.52.91.14 Probable Submitter: 2a01:118f:4f9:5400:7838:2450:eebb:f59b ---- Manual Page -- http://php.net/manual/en/function.array.php Edit -- https://master.php.net/note/edit/117137 Del: integrated -- https://master.php.net/note/delete/117137/integrated Del: useless -- https://master.php.net/note/delete/117137/useless Del: bad code -- https://master.php.net/note/delete/117137/bad+code Del: spam -- https://master.php.net/note/delete/117137/spam Del: non-english -- https://master.php.net/note/delete/117137/non-english Del: in docs -- https://master.php.net/note/delete/117137/in+docs Del: other reasons-- https://master.php.net/note/delete/117137 Reject -- https://master.php.net/note/reject/117137 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#202306) next »