0

I have some array of objects like this

$names=Array ( [0] => stdClass Object ( [id] => 1 
                                        [heading_de] => Title_Deutch 
                                        [heading_en] => Title_English );

And i have some var like

$lang="_en";

When i want to try something like this

foreach ($names as $title)
        {

         $title = $title->heading.$lang;
        }

I only got

$title="_en"

But when i try something like this

foreach ($names as $title)
        {

         $title = $title->heading_en;
        }

I got it ok, where is my mistake, hot to combine string and object ?

1
  • 1
    Are you looking for $title->{'heading' . $lang}? Commented Apr 6, 2014 at 17:54

1 Answer 1

4

You want to use variable variables in php, try the following

  $lang = "_en";
  foreach ($names as $title) {
    echo $title->{'heading' . $lang};
  }
Sign up to request clarification or add additional context in comments.

Comments

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.