Bayu Angga Satrio Bayu Angga Satrio - 1 month ago 5
PHP Question

codeigniter: how to access more than one variable of other functions in one class?

For example I have a class like this

public function data() {
$a = 1;
$b = 2;
$c = 3;
}

public function codeigniter() {
$a, $b, $b //how i can get the value??
}


How can I get the value of
$a
,
$b
,
$c
so that I can use it in
codeigniter()
function? I use codeigniter? Do I need to add a
return;
?

Answer

First create a array and store the values in it and return the array.

public function data() {
    $data = array();
    $data['a']=1;
    $data['b']=2;
    $data['c']=3;
    return $data;
}

Then you can simply call the function and access the returned data.

    public function codeigniter() {
     $data_value = $this->data();

          echo $data_value['a'];
          echo $data_value['b'];
          echo $data_value['c'];
      }
Comments