$arr = ['fruit' => 'apple', 'veggie' => 'carrot']; // Способ 1. echo "Hello {$arr['fruit']}"; // Способ 2. echo "Hello $arr[fruit]"; 

Do constants always do not work inside strings?

  • You give the third option? )))) really doesn't matter)))) - Shnur
  • Shnur Do constants always work inside strings? - user208916
  • what constants? Best of all through concatenation, more readable, especially in the IDE. - Jean-Claude
  • @ Jean-Claude This is an idea. - user208916
  • and then there will be highlighting of array indices (phpstorm), then fruit or veggie should not be completely written. - Jean-Claude

1 answer 1

You can still

 echo "Hello ".$arr[fruit]; 
  • No, it is not necessary. - user208916
  • Then I do not understand what the question is, both of the top options are working. And actually no matter how - NTP