7

When object name ( category ) put directly it returns correct value Like:

 $primary = $this->dbmapper->category['primary'] ;  // ( Correct Output )

But when , put object name in a variable called $dataname, it returns blank, like:

 $dataname = 'category';
 $primary = $this->dbmapper->$dataname['primary'] ;   ( Blank Output )

my constructor variable is:

  $this->dbmapper = $this->mapper();

My function is:

  function mapper($module='')
    {
        $mapper =  array();
        $mapper['category']['table'] = 'allcategory';
        $mapper['category']['primary'] = 'categoryID';
        $mapper['page']['table'] = 'allpages';
        $mapper['page']['primary'] = 'pageID';
        return (object) $mapper;
    }
0

1 Answer 1

5

To access an object property(especially if it's an array) via variable enclose it with braces:

...
$dataname = 'category';
$primary = $this->dbmapper->{$dataname}['primary'];
Sign up to request clarification or add additional context in comments.

1 Comment

:) Works for me , Thanks

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.