Q:

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;?

A:

I assume the two function are in both class and in a controller class of codeigniter
class Sample extends CI_Controller {
// declare variables
    public $a;
    public $b;
    public $c;

    public function __construct() {
        // call codeigniter method
        $this->codeigniter();
    }

    public function data() {
        $this->a = 10;
        $this->b = 11;
        $this->c = 12;
    }

    public function codeigniter() {

        // call method data();

        $this->data();

        echo $this->a; // prints 10
        echo $this->b; // prints 11
        echo $this->c; // prints 12

    }

}

A:

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'];
      }

