0

My target is to assign a number to the string in the array.

  $lang = array (
    'title'         => "Der Anti-Spam Dienst",
    'button-login'  => "Jetzt $number via Twitter anmelden."
   );

The $number should be set like $lang['button-login'][5] - but I don't have any idea how to access the variable in the array. maybe you can help me.

Thanks!

1 Answer 1

3

You should declare the $number variable before the array:

$number = 5;

$lang = array(
    'title'         => "Der Anti-Spam Dienst",
    'button-login'  => "Jetzt $number via Twitter anmelden."
);

Update: If you want to set it afterwards, you'll have to use str_replace:

$lang = array(
    'title'         => 'Der Anti-Spam Dienst',
    'button-login'  => 'Jetzt $number via Twitter anmelden.'
);

echo str_replace('$number', 5, $lang['button-login']);

See it here in action: http://viper-7.com/7QtpF7

Note: the strings should be surrounded by single quotes, so that $number is not parsed as a variable.

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

2 Comments

Thats the point, I want to set the $number variable while i want to get the string for button-login. Do you think its possible? (Thanks so far)
@H3rrVorr4g3nd - Not sure I fully understand what you're trying to do. If you want to do it afterwards, see my update.

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.