Hi,
I've been recently trying to create a language change script. Everything goes smoooth but there are several complexed places inside the page that needs some advanced php code.
So the main problem is: I do not know how to make a variable from main page work in array.

    $eng = array(
        'cp_ver' => 'v1.0.1 ',
        'cp_title' => 'Control Panel ',
        'cp_sub' => 'Welcome to central controll center. ',
        'logout_btn' => 'Logout ',
        'no_profiles' => 'You do not have a profile yet. ',
        'profile_permission' => 'You belong to ' . $group . ' with a permission of ' . $permission .'',
    );

profile_permission property is like a real pain in the hole for me right now.
this code is located in a langs.php file which is included into main page index.php.
Please help me to sort this out.

Hi, you can use sprintf for this task:

echo sprintf($eng['profile_permission'], $group, $permission);

However before doing this you need to change the variables in the array with the value types, in your case:

$eng['profile_permission'] = 'You belong to %s with a permission of %s';

Where %s stands for string, here the documentation:

Bye!

Maybe the simplest way would be to address the array element directly:

$eng['profile_permission'] = 'You belong to ' . $group . ' with a permission of ' . $permission .'';

or using double quotes:

$eng['profile_permission'] = "You belong to $group with a permission of $permission";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.