jamesxg1 Posted February 19, 2010 Share Posted February 19, 2010 Hiya peeps! How do I use a var in an array. You will see $id but it isnt working. array('MAINCONTENT' => '<div id="registration"><form id="register" class="cssform" action="#" method="POST"> <b><font color="black" size="4">Personal Details</font></b> <p> <label for="firstname">First Name</label> <input type="text" id="firstname" value="" autocomeplete="off" /> </p> <p> <label for="lastname">Last Name</label> <input type="text" id="lastname" value="" autocomeplete="off" /> </p> <p> <label for="emailaddress">Email Address:</label> <input type="text" id="emailaddress" value="" autocomeplete="off" /> </p> <p> <label for="password">Password:</label> <input type="password" id="password" value="" autocomeplete="off" /> </p> <p> <label for="passwordconf">Confirm Password:</label> <input type="password" id="passwordconf" value="" autocomeplete="off" /> </p> <p> <label for="phone">Phone:</label> <input type="text" id="phone" value="" autocomeplete="off" /> </p> <p> <label for="address">Address:</label> <input type="text" id="address" value="" autocomeplete="off" /> </p> <p> <label for="city">City:</label> <input type="text" id="city" value="" autocomeplete="off" /> </p> <p> <label for="county">County:</label> <input type="text" id="county" value="" autocomeplete="off" /> </p> <p> <label for="postcode">Postcode:</label> <input type="text" id="postcode" value="" autocomeplete="off" /> </p> <p></p> <b><font color="black" size="4">Card Details</font></b> <p> <label for="accname">Name on card:</label> <input type="text" id="accname" value="" autocomeplete="off" /> </p> <p> <label for="accnumber">Account number:</label> <input type="text" id="accnumber" value="" autocomeplete="off" /> </p> <p> <label for="accsort">Account sort code:</label> <input type="text" id="accsort" value="" autocomeplete="off" /> </p> <p> <label for="expiry">Expiry:</label> <input type="text" id="expiry" value="" autocomeplete="off" /> </p> <div style="margin-left: 200px;"> <input type="text" id="id" value="$id" autocomeplete="off" /> <input type="submit" value="Submit" /> </div> </form></div>'); Many thanks James. Link to comment https://forums.phpfreaks.com/topic/192578-how-do-i-use-vars-in-an-array/ Share on other sites More sharing options...
jamesxg1 Posted February 19, 2010 Author Share Posted February 19, 2010 B to the U to the M to the P. Link to comment https://forums.phpfreaks.com/topic/192578-how-do-i-use-vars-in-an-array/#findComment-1014599 Share on other sites More sharing options...
roopurt18 Posted February 19, 2010 Share Posted February 19, 2010 You're trying to use a variable inside of a single-quoted string, which won't work. The fact that the single-quoted string is a value in an array is irrelevant. You'll want to use string concatenation at the point where you want to use the variable if you want to stick with a single-quoted string. Link to comment https://forums.phpfreaks.com/topic/192578-how-do-i-use-vars-in-an-array/#findComment-1014600 Share on other sites More sharing options...
jamesxg1 Posted February 19, 2010 Author Share Posted February 19, 2010 You're trying to use a variable inside of a single-quoted string, which won't work. The fact that the single-quoted string is a value in an array is irrelevant. You'll want to use string concatenation at the point where you want to use the variable if you want to stick with a single-quoted string. Hiya bud, Thanks for the reply. I only really understood the first half of that LOL! My brain is not fully functional right now LOL! Many thanks James. Link to comment https://forums.phpfreaks.com/topic/192578-how-do-i-use-vars-in-an-array/#findComment-1014604 Share on other sites More sharing options...
roopurt18 Posted February 19, 2010 Share Posted February 19, 2010 $example_single_quoted_string = 'hello there, my id is $id. cool, huh?'; // this does not work // so we end the string with a single quote, use concatenation with our variable, and then start the string again $example_single_quoted_string = 'hello there, my id is ' . $id . '. cool, huh?'; Link to comment https://forums.phpfreaks.com/topic/192578-how-do-i-use-vars-in-an-array/#findComment-1014606 Share on other sites More sharing options...
jamesxg1 Posted February 19, 2010 Author Share Posted February 19, 2010 $example_single_quoted_string = 'hello there, my id is $id. cool, huh?'; // this does not work // so we end the string with a single quote, use concatenation with our variable, and then start the string again $example_single_quoted_string = 'hello there, my id is ' . $id . '. cool, huh?'; Ah right I see LOL! It worked! Cheers for that mate. Many thanks, James. Link to comment https://forums.phpfreaks.com/topic/192578-how-do-i-use-vars-in-an-array/#findComment-1014608 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.