Question

I was looking at some source code, specifically for Paypal IPN, and I noticed the author sets two variables in this format: $config['business'] and $config['different_text']

Is there a special reason other than the obvious organization for declaring my variables this way or is this Paypal settings?

Was it helpful?

Solution

This syntax is used to access elements of an array -- see Arrays in the PHP manual.


Here, you are working with an associative array, called $config, that's contain at least two entries : business and different_text.


Considering the name of the $config variable, you have at least two advantages :

  • related variables are grouped together in one variable -- easier to have them together
  • only one variable ($config) to work with

And, of course :

  • You can add any number of configuration options without having to create a new variable : just add a new element to the $config array.


That being said, of course, maybe the paypal API you are using is actually expecting some data passed as an associative array containing those elements -- if it is the case, you don't have much of a choice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top