0
我有一個可以創建6個數組的表單。他們的高度和寬度,我需要多個。從數組中乘以數值
Array1[0] * Array2[0]
Array3[0] * Array4[0]
Array5[0] * Array6[0]
我可以讓數組單獨打印,但我不能讓計算工作。
extract($_REQUEST);
if(count($_POST)!=0){
foreach($_POST as $key=>$value){
if(gettype($value) == "array"){
$i=0;
$total = array();
foreach($picw as $key=>$width){
$total[] = $width * $pich[$key];
echo $total;
}
/*foreach($value as $v){
$i++;
//echo "<div>{$key}{$i}: " . ${"{$key}{$i}"} = $v . "</div>";
${"{$key}{$i}"} = $v;
$pic{$i} = $picw{$i} * $pich{$i};
}*/
}
}
}
這裏是什麼陣列打印:
pich=>Array pich1: 12
picw=>Array picw1: 12
hungh=>Array hungh1: 12
hungw=>Array hungw1: 12
sliderh=>Array sliderh1: 12
sliderw=>Array sliderw1: 12
編輯:這裏是形式,其中名來自
<form action="windowQuoteEnd.php" method="post">
<table>
<td colspan="3"><b>Picture Window Quantity:</b></td>
<td><select name="picq" id="picq" class="dynamicAdder" data-selector="#pic_dup_1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select></td>
</tr>
<!-- DUPLICATES BASED ON THE SELECTION ABOVE - NUMBERS INCRIMENT FOR EACH ADDED SELECTION WHERE THE 1 IS NOW -->
<tr id="pic_dup_1">
<td><select name="pich[]" id="pich1">
<option value="12">12</option>
<option value="24">24</option>
<option value="36">36</option>
<option value="48">48</option>
<option value="60">60</option>
<option value="72">72</option>
<option value="84">84</option>
<option value="96">96</option>
<option value="108">108</option>
</select></td>
<td> x </td>
<td><select name="picw[]" id="picw1">
<option value="12">12</option>
<option value="24">24</option>
<option value="36">36</option>
<option value="48">48</option>
<option value="60">60</option>
<option value="72">72</option>
</select></td>
</tr>
<!-- END DUPLICATE -->
<tr>
<td colspan="3"><b>Single Hung Window Quantity:</b></td>
<td><select name="shq" id="shq" class="dynamicAdder" data-selector="#hung_dup_1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select></td>
</tr>
<!-- DUPLICATES BASED ON THE SELECTION ABOVE - NUMBERS INCRIMENT FOR EACH ADDED SELECTION WHERE THE 1 IS NOW -->
<tr id="hung_dup_1">
<td><select name="hungh[]" id="hungh1">
<option value="12">12</option>
<option value="24">24</option>
<option value="36">36</option>
<option value="48">48</option>
<option value="60">60</option>
<option value="72">72</option>
<option value="84">84</option>
<option value="96">96</option>
<option value="108">108</option>
<option value="120">120</option>
</select></td>
<td> x </td>
<td><select name="hungw[]" id="hungw1">
<option value="12">12</option>
<option value="24">24</option>
<option value="36">36</option>
<option value="48">48</option>
<option value="60">60</option>
<option value="72">72</option>
</select></td>
</tr>
<!-- END DUPLICATE -->
<tr>
<td colspan="3"><b>Patio Slider Quantity:</b></td>
<td><select name="psq" id="psq" class="dynamicAdder" data-selector="#test_dup_1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select></td>
</tr>
<!-- DUPLICATES BASED ON THE SELECTION ABOVE - NUMBERS INCRIMENT FOR EACH ADDED SELECTION WHERE THE 1 IS NOW -->
<tr id="test_dup_1">
<td><select name="sliderh[]" id="sliderh1">
<option value="12">12</option>
<option value="24">24</option>
<option value="36">36</option>
<option value="48">48</option>
<option value="60">60</option>
<option value="72">72</option>
<option value="84">84</option>
<option value="96">96</option>
<option value="108">108</option>
<option value="120">120</option>
</select></td>
<td> x </td>
<td><select name="sliderw[]" id="sliderw1">
<option value="12">12</option>
<option value="24">24</option>
<option value="36">36</option>
<option value="48">48</option>
<option value="60">60</option>
<option value="72">72</option>
</select></td>
</tr>
<!-- END DUPLICATE -->
<tr>
<td colspan="2"><button name="Submit" type="Submit" value="Submit">Get Quote</button></td>
</tr>
</table>
這裏是JQuery的...
<script>
$(document).ready(function()
{
$('.dynamicAdder').each(function(i,e)
{
var selector = $(e).attr('data-selector');
var id = $(selector).attr('id');
$(selector).addClass($(selector).attr('id')).removeAttr('id');
$(e).attr('data-selector','.'+id);
$(e).on('change',function()
{
var selector = $(this).attr('data-selector');
var qty = $(this).val();
var len = $(selector).length;
for(var x=len;x<qty;x++)
{
var clone = $(selector).last().clone();
$(selector).last().after(clone);
}
if(len>qty)
{
var diff = len-qty; // extra rows , delete them in the next step
for(var y=0;y<diff;y++)
{
$(selector).last().remove();
}
}
});
});
});
</script>
請告訴我您的實際'$ array'定義是什麼? –
你是什麼意思? – BKCOHEN
'$ pich'和'$ picw'從哪裏來? – CodeBird