Vivid Lust Posted August 26, 2009 Share Posted August 26, 2009 Hey all, I have a language system and have decided to store a list of languages as follows: <?php //Languages DEFINE('Lang1','Afrikaans'); DEFINE('Lang2','Akan'); DEFINE('Lang3','Albanian'); DEFINE('Lang4','Amharic (Ethiopian)'); DEFINE('Lang5','Arabic, Egyptian'); // etc etc ?> And then im displaying them in a drop down box as: <?php for ( $counter = 1; $counter <= 130; $counter += 1) { echo '<option value="'.$counter.'" >'; echo Lang.$counter; echo '</option>'; } ?> However PHP doesnt recognise what I put is a defined varibale and instead echos "Lang1", "Lang2" etc. Any help? Thanks Link to comment https://forums.phpfreaks.com/topic/171992-solved-creating-a-defined-variable-from-anoter-variable-and-text/ Share on other sites More sharing options...
Asheeown Posted August 26, 2009 Share Posted August 26, 2009 Take away the period, I've done it with defining dynamic variables without the period: echo Lang$counter; Link to comment https://forums.phpfreaks.com/topic/171992-solved-creating-a-defined-variable-from-anoter-variable-and-text/#findComment-906889 Share on other sites More sharing options...
Vivid Lust Posted August 26, 2009 Author Share Posted August 26, 2009 I now get this: Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /home/penpal/public_html/signup.php on line 18 Edited Code: <?php for ( $counter = 1; $counter <= 130; $counter += 1) { echo '<option value="'.$counter.'" >'; echo Lang$counter; echo '</option>'; } ?> Link to comment https://forums.phpfreaks.com/topic/171992-solved-creating-a-defined-variable-from-anoter-variable-and-text/#findComment-906892 Share on other sites More sharing options...
Asheeown Posted August 26, 2009 Share Posted August 26, 2009 echo constant("Lang" . $counter); give that a go Link to comment https://forums.phpfreaks.com/topic/171992-solved-creating-a-defined-variable-from-anoter-variable-and-text/#findComment-906894 Share on other sites More sharing options...
Vivid Lust Posted August 26, 2009 Author Share Posted August 26, 2009 Works now, thanks sooo much!! Link to comment https://forums.phpfreaks.com/topic/171992-solved-creating-a-defined-variable-from-anoter-variable-and-text/#findComment-906897 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.