Jump to content

$array['var'] vs $array[var]


alin19

Recommended Posts

Nothing to change in php.ini

 

echo $array['var']; should always work, as long as $array['var'] exists.

 

echo  $array[var]; will give you a warning unless you have a constant called var. If you don't, it will assume that you meant 'var' instead, and act accordingly; but it still generates the warning to let you know you've done something wrong.

 

Link to comment
https://forums.phpfreaks.com/topic/144610-arrayvar-vs-arrayvar/#findComment-758826
Share on other sites

As Mark Baker pointed out, it better to fix the errors because disabling NOTICES can effect other problems especially if you have registered globals on. But if you must disable the notice so you can use [var] or ['var'], then...

 


// in your script..

error_reporting ( E_ALL ^ E_NOTICE );


// or php.ini

error_reporting = E_ALL ^ E_NOTICE

Link to comment
https://forums.phpfreaks.com/topic/144610-arrayvar-vs-arrayvar/#findComment-758828
Share on other sites

Must be a homework question - http://www.phpfreaks.com/forums/index.php/topic,238023.0.html

 

The answer is - you don't change anything in your php.ini to fix code that is using the second form (without quotes), you fix your code to use the correct syntax.

Link to comment
https://forums.phpfreaks.com/topic/144610-arrayvar-vs-arrayvar/#findComment-758847
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.