0

I have the following array...generated from this code.

$aa = new_Arr();

print_r($aa);   //here is the result...


     cl_aa Object
    (
        [data:cl_aa:private] => Array
            (
                [t_a] => Array
                    (
                        [0] => Array
                            (
                                [f_c] => LAL
                                [p_r] => RN
                                [id] => 1214125
                                [gender] => m
                            )
                    )

                [t_b] => Array
                    (
                    )

                [t_l] => Array
                    (
                        [0] => Array
                            (
                                [p_lev] => 2
                                [p_date] => 
                                [p_r] => 
                            )
                    )

                [t_r] => Array
                    (
                        [0] => Array
                            (
                                [I_r] => 19
                            )

                    )

            )

        [db:cl_aa:private] => PDOTester Object
            (
            )
    )

I try to read it as like this...

foreach ($aa as $key=>$value) {
     print_r($key);
     echo "<h1>". $value['bb']. "</h1>";
 }

but no result i can see...

how do I read the above array? Help please?

8
  • 1
    If your objects are private, you can't access them from outside their class without getters. Commented Aug 6, 2013 at 14:19
  • 2
    Make them public for example? Commented Aug 6, 2013 at 14:21
  • Either make them public or create getters in your class. I suggest you have a look at php.net/manual/en/language.oop5.php Commented Aug 6, 2013 at 14:22
  • The difference with getters would be that the values cannot be changed outside of the given class (without any setters). Decision between public and getters will be based on your particular case. Commented Aug 6, 2013 at 14:23
  • there is no way to change from private to public, some other idea please? Commented Aug 6, 2013 at 14:23

1 Answer 1

1

Provide your cl_aa class some getters :

public class cl_aa {

    private $data;
    private $db;

    public function getData() {
        return $this->data;
    }
    public function getDb() {
        return $this->db;
    }
}

And to access your data from outside :

$aa = new_Arr(); // I assume this function returns a cl_aa object.
print_r($aa->getData());
print_r($aa->getDb());

Take a look at this link to learn more about OOP.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that solves my problem...the getter Method..Thanks Mr.Yellow Bird. you really are yellow...ohhhhh, thanks anyway...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.