php - foreach loop using $this as key and value -



php - foreach loop using $this as key and value -

i want create foreach loop one

foreach ($this->data['array'] $this->data['key'] => $this->data['value']) { echo $this->data['value']; }

yet $this->data['value'] never created. why , doing wrong?

in understanding, have class in there variable or array name $data.

now, added array in $data index named 'array', right? if so, code work -

class myclass{ public $data = array(); //$data array function print_array(){ foreach ($this->data['array'] $this->data['key'] => $this->data['value']) { echo $this->data['value']; } } } $ob = new myclass(); // object declaration class array_push($ob->data,'array'); // added value $data array. $ob->data['array'] = array(); // newly added value declared index of array // force values array named $data['array'] array_push($ob->data['array'],1); array_push($ob->data['array'],2); array_push($ob->data['array'],3); $ob->print_array(); // phone call print_array() function. $this passed function

hope help understand. if still have problem, please comment. have clear understanding, can visit this link. there lots of simple , interesting examples explained!

happy coding!

php

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -