I've following PHP code:
<?php
$rebate_no = 2;
echo "<table id='blacklistgrid_$rebate_no' class='table table-bordered table-hover table-striped blacklistgrid'>
<tr id='reb$rebate_no_1'>
<td>
<div class='btn-group'>
<select name='product_id_$rebate_no[1]' id='product_id_$rebate_no_1' class='form-control prod_list'>
<option value='1'>Alabama</option>
<option value='2'>Alaska</option>
<option value='3'>Arizona</option>
<option value='4'>Arkansas</option>
<option value='5'>California</option>
</select>
</div>
</td>
</tr>
</table>";
?>
In above code I'm having issues in concatenation of variable and string at following lines:
<tr id='reb$rebate_no_1'>
<select name='product_id_$rebate_no[1]' id='product_id_$rebate_no_1' class='form-control prod_list'>
I tried following trick but it didn't work for me.
<tr id='reb'.$rebate_no.'_1'>
<select name='product_id_$rebate_no[1]' id='product_id_'.$rebate_no.'_1' class='form-control prod_list'>
If I check in HTML source I'm getting following HTML:
<tr id="reb" .2.'_1'="">
<select id="product_id_" class="form-control prod_list" .2.'_1'="" name="product_id_">
Actually I want the HTML in following desired format:
<tr id='reb2_1'>
<select name='product_id_2[1]' id='product_id_2_1' class='form-control prod_list'>
How to achieve this? Thanks in advance.
You started with double quotes, so you can do it this way:
or use curly braces
{}
around the variable:Both are valid.
Try this:
when you are concating the string you need use double quotes since you started string with double quotes.
There is easiest method Use (" ") double quotes instead of (' ') without making it complicated.
instead of
Reff : PHP: different quotes?
String concatenation
OR If you want to use the Zend specification
the problem lies with
$rebate_no[1]
. you can either store the value of that into a regular variable, append the value to the string like below, or surround it in curly brackets like so{$rebate_no[1]}
you got the trick wrong.
instead of doing
do