-2

I have the following -

function button_class_add() {
    global $uno_dos;
    $btn_shape_class = $uno_dos['buttons-shape-select-general'];
    $btn_size_class = $uno_dos['buttons-size-select-general'];
    ?>
        <script type="text/javascript">
            jQuery(function($) {
                $('.std-button').addClass('<?php echo $btn_shape_class $btn_size_class; ?>');
            });
        </script>
<?php }

add_action('wp_footer', 'button_class_add');

How can I correctly combine these 2 variables so I can just echo out the combined variable?

$btn_shape_class = $uno_dos['buttons-shape-select-general'];
$btn_size_class = $uno_dos['buttons-size-select-general'];

Many thanks

Combining these lines -

$btn_shape_class = $uno_dos['buttons-shape-select-general'];
$btn_size_class = $uno_dos['buttons-size-select-general'];

Into something like -

$btn_shape = $uno_dos['buttons-shape-select-general']$uno_dos['buttons-size-select-general'];

Then I can just echo the 1 variable.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339

2 Answers2

2

You can just use the "." string operator:

http://php.net/manual/en/language.operators.string.php

$combined = $btn_shape_class.$btn_size_class

or if you want to have a whitespace between, like in your current code:

$combined = $btn_shape_class.' '.$btn_size_class
Daniele D
  • 838
  • 1
  • 8
  • 21
0

It looks like by "combine", you mean "concatenate". Concatenating allows you to append a string to the end of another string.

If you want to concatenate two variables with different values then you just use a fullstop as follows:

// $variable_1 = 'hot';
// $variable_2 = 'dog';

echo $variable_1 . $variable_2;
// 'hotdog'

If you want to add whitespace between the two variables, on the other hand, you would need to concatenate the whitespace as follows:

// $variable_1 = 'hot';
// $variable_2 = 'dog';

echo $variable_1 . ' ' . $variable_2;
// 'hot dog'
Chris Forrence
  • 10,042
  • 11
  • 48
  • 64
Coderrrr
  • 230
  • 1
  • 16
  • Have updated my original question. Thanks – DaThemeDude Apr 09 '15 at 14:21
  • Hi, I think by combine you do mean concatenate, concatenating basically allows you to append a string to the end of another string. So if we had 2 variables with different values that we want to join we would concatenate like so. $str_1 = 'hot'; $str_2 = 'dog'; and then we concatenate like so : echo $str_1 . $str_2; that gives us hotdog. Please let me know if this is not what you meant but I think it should help. – Coderrrr Apr 09 '15 at 15:12
  • 1
    This isn't an answer. To request clarification, comment on the original post. – Jimbo Apr 10 '15 at 14:21
  • What do you mean, I answered the question and asked for clarification if it was what he had asked? next you're going to say it wasn't a question because he didn't put a question mark at the end – Coderrrr Apr 10 '15 at 14:42
  • 1
    Heya @Coderrrr! I edited your question to remove the clarification part; this answer had come up in the Low Quality Posts queue, primarily for that reason (from what it appears). – Chris Forrence Apr 10 '15 at 18:19
  • @Coderrrr Before the answer was edited, you were asking questions in your answer. The answer is meant to be *definitive*. You were asking for clarification which belongs in a comment. In the future, try not to post an answer when you need more information to actually answer, you'll get downvoted for it. To re-iterate, ***any*** questions whatsoever do not belong in an answer (your answer appeared in the "low answer quality" queue which people like me go through and make a decision on). – Jimbo Apr 11 '15 at 15:11