PHP retrieving array values using dash arrow "->" -


i've been using php quite while now, never been advanced programmer. feel dumb question never understood why array values can retrieved using different methods:

this:

$array->value 

rather normal:

$array['value'] 

the standard $array['value'] works, 1 using -> method doesn't @ times. why that?

here's example. using zend framework 2 , can grab session value using -> method:

$this->session->some_value 

however, can't if new, normal array:

$array = array('some_value' => 'myvalue'); $array['some_value']; // works!! $array->some_value;  // not work :( 

in zend framework 1 arrays work fine way, , in zf2 more , more , run issues need change way value. make sense? sure appreciate help. thanks, greg

as stated before in other answers, using -> means accessing object, not array.

however, possible object treated array. when implementing arrayaccess interface. coder can such eg. calling $object->field equivalent $object['field'], he/she must not.

moreover, possible treat array object (refer to manual), in case not array object , same way above.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -