When you instantiate an object in PHP code it is sometimes desirable to allow for variable parameter setting combinations to create the object. Although this can be done using default parameters passed to the constructor this can become messy when too many variables are available to be set. A simpler approach is to allow for an associative array to be passed to the constructor as in the example below.
class MyClass { protected $_name = 'Bob' ; protected $_address = 'Penny Lane' ; protected $_phone = '555-555-5555' ; public function __construct ($config = array ()) { if (array_key_exists ('name', $config)) $this->_name = $config ['name'] ; if (array_key_exists ('address', $config)) $this->_address = $config ['address'] ; if (array_key_exists ('phone', $config)) $this->_phone = $config ['phone'] ; }
Although this is a trivial example it demonstrates how to leverage an array passed to a constructor class to initialize a PHP variable. This is a useful technique that can be employed when building re-usable classes to power your applications.

