Oleksii
Oleksii

Reputation: 59

Variable in array key

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']"].'"
            }';

Upvotes: 2

Views: 86

Answers (2)

Oleksii
Oleksii

Reputation: 59

Solution in my case:

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

Thanx:)

Upvotes: 0

gazdagergo
gazdagergo

Reputation: 6691

Just simple concatenate:

 $data['checkout_' . $lang] 

Upvotes: 2

Related Questions