2

Have array $data with keys like checkout_en, checkout_ru and have var $lang with two variants ru and en.

How can i make smht like this $data['checkout_$lang'] to make key checkout_en or checkout_ru depends on $lang var value.

Thank you!

my code

$msg = '"buttons": [
            {
              "block_names": ["'.$settings['checkout_block_name'].'"],
              "type":"show_block",
              "title":"'.$settings["checkout_$settings['user_lang']"].'"
            }';
6
  • 2
    try $data['checkout_' . $lang] Commented Aug 8, 2018 at 5:57
  • Can you give the sample of the both array variables Commented Aug 8, 2018 at 5:58
  • Or $data["checkout_$lang"] Note use of double quotes, not single as you have in the question. Commented Aug 8, 2018 at 5:58
  • $data['checkout_'.$lang] @ZainFarooq you need to remove last quote Commented Aug 8, 2018 at 5:58
  • 1
    Possible duplicate of What is the difference between single-quoted and double-quoted strings in PHP? Commented Aug 8, 2018 at 6:32

2 Answers 2

2

Just simple concatenate:

 $data['checkout_' . $lang] 
Sign up to request clarification or add additional context in comments.

Comments

0

Solution in my case:

   {
     "block_names": ["$settings[start_block_name]"],
     "type":"show_block",
     "title":"'.$settings["back_to_shop_$settings[user_lang]"].'"
    }

Thanx:)

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.