PHP: Return property in array format and get value -


i want value in array format various keys method.

class file

<?php class hooks {      private $version = '1.4';     public $hook = array();       public function __construct(){ }       public function get_item_hook()     {         //bla bla bla         $this->hook['foo']  = 'resulting data foo';         $this->hook['foo1'] = 'resulting data foo1';         $this->hook['foo2'] = 'resulting data foo2';          return $this->hook;     }      public function get_item2_hook()     {         //bla bla bla         $this->hook['another']  = 'resulting data another';         $this->hook['another1'] = 'resulting data another1';         $this->hook['another2'] = 'resulting data another2';          return $this->hook;     }   } ?> 

code file

<?php // in file  include ('path above class file');  $hook = new hooks; $hook->get_item_hook();  //now how can value of $this->hook array()???  $hook->get_item2_hook();  //now how can value of $this->hook array()??? ?> 

you aren't capturing return value when call methods.

try

$myarray = $hook->get_item_hook(); // ^^ here store return value  print_r($myarray); echo $myarray['foo']; // resulting data foo 

also bountyh points out, missed function keyword in methods:

public function get_item_hook() {     ... } 

if turn on php errors or check error log, should seeing error:

parse error: syntax error, unexpected t_string, expecting t_variable ...

to turn errors on:

error_reporting(e_all); ini_set('display_errors', '1'); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -