arrays - Using php, how to get return object data into variable? -
i have read number of answers on not getting something. have object retrieves data file , puts array format , trying data variable in calling file can work data.
calling.php $x = new obj(); $x -> method_y(); objectfile.php public function method_y(){ ..... code stuff ..... print_r($array); } array( [0] => array ( [key1] => value1 [key2] => value2 [key3] => value3 ) [1] => array ( [key1] => value1 [key2] => value2 [key3] => value3 ) )
is better use echo, return, or print method , should use json_encode return it. how returned data out of object can work with. instance using json_encode in method json json_decode wants string.
again have read number of answers on not getting it.
thanks in advance.
you can return array itself, , traverse array using loops, maybe this
public function method_y(){ ..... code stuff ..... return $array; } $var = $x -> method_y(); foreach($var $element) { foreach($element $key => $value) { echo $key; echo $value; } }
Comments
Post a Comment