Why does $$ var ['namedIndex'] = 'test' not work?

In PHP you can

$var = 'title';
$$var = 'my new title'; 

and it works great. But when you try to use it with an array, it does not work and no error messages are reported.

$var = 'title';
$$var['en'] = 'my english title';

$var = 'description';
$$var['en'] = 'my english description';

thanks for the help

[EDIT] If I do

$$var = array();
array_push($$var,'test');

it works and displays

title[0] = 'test';

But I really need a named index: /

+3
source share
2 answers

write like this:

${$var}['en']

from documents:

, . , $$ a 1, , $a 1 , $$ a , 1 index from . : ${$ a 1} ${$ a} 1 .

+4

:

${$var}['en']

, , . $$var['en'], $var['en'], . ${$var}['en'] , $var.

+2

Source: https://habr.com/ru/post/1721544/


All Articles