i am trying to concatenate values into a string which later is attached to a hidden input.
This is the forach loop:
<?php
$langid = array();
$transLang = '';
foreach($translator['langs'] as $lang) {
$curlang = $lang->term_id;
$langid[] = $curlang;
$transLang .= '('.$curlang.'), ';
// for testing
echo $transLang."<br />";
}
?>
<input type="hidden" name="selectedLang" value="<?php echo $transLang; ?>" />
.
The langid[] array grabs everything correctly
but $transLang echoed into the input only shows the first value which is: (3),
When i use this line:
echo $transLang."<br />";
Which i added for testing it echoes:
(3),
(3), (10),
(3), (10), (12),
(3), (10), (12), (27),
(3), (10), (12), (27), (19),
(3), (10), (12), (27), (19), (20),
The last one is the complete string after the foreach finished runing but the input field value is always only the first run meaning (3),
Any idea why this is happening?