الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كيف يمكن جمع Total؟؟

بدأه العسولة في 1 مارس 2011 · 3 رد · 444 مشاهدة · في منتدى تطوير المواقع بـ PHP
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

أخباركم ؟؟ في هذا الكود استخدمت while مع each ،،، ولكن كيف يمكن ان نتمم عملية الجمع ،،

<?php

$items=array(0=>array('Item'=>'Tea','Price'=>'1.250','Quantity'=>'3'),

1=>array('Item'=>'Coffee','Price'=>'2.5','Quantity'=>'5'),

2=>array('Item'=>'Rice','Price'=>'5','Quantity'=>'1'));

echo"<table border=3 width=400 bgcolor=lightgreen align=center>";

echo"<tr><th align=center>Item</th>

<th align=center>Price</th>

<th align=center>Quantity</th>

<th align=center>Total</th>

</tr>";

$gtotal=0;

while($myarray=each($items))

{

$total=$v[Quantity]* $v[Price];//Count total for the Current Item

$gtotal += $total; //Calculate the Grand Total

echo"<tr><td align=center>{$myarray[1]['Item']}</td>

<td align=center>{$myarray[1]['Price']}</td>

<td align=center>{$myarray[1]['Quantity']}</td>

<td align=center>$total</td>

</tr>";

}

echo"<tr><th colspan=3 align=left>Total</th><th>$gtotal</th> </tr>";

echo "</table>";

?>

#2

الكود باستعمال foreach

<?php
$items=array(
			0=>array('Item'=>'Tea','Price'=>'1.250','Quantity'=>'3'),
			1=>array('Item'=>'Coffee','Price'=>'2.5','Quantity'=>'5'),
			2=>array('Item'=>'Rice','Price'=>'5','Quantity'=>'1')
		);
echo"<table border=3 width=400 bgcolor=lightgreen align=center>";
echo"<tr><th align=center>Item</th>
	<th align=center>Price</th>
	<th align=center>Quantity</th>
	<th align=center>Total</th>
	</tr>";

$gtotal = 0;
foreach($items as $item)
{
	$total = $item['Quantity'] * $item['Price'];//Count total for the Current Item
	$gtotal += $total; //Calculate the Grand Total
	echo"<tr><td align=center>{$item['Item']}</td>
	<td align=center>{$item['Price']}</td>
	<td align=center>{$item['Quantity']}</td>
	<td align=center>$total</td>
	</tr>";
}
echo"<tr><th colspan=3 align=left>Total</th><th>$gtotal</th> </tr>";
echo "</table>";

?>
#3
herch كتب:

الكود باستعمال foreach

<?php
$items=array(
			0=>array('Item'=>'Tea','Price'=>'1.250','Quantity'=>'3'),
			1=>array('Item'=>'Coffee','Price'=>'2.5','Quantity'=>'5'),
			2=>array('Item'=>'Rice','Price'=>'5','Quantity'=>'1')
		);
echo"<table border=3 width=400 bgcolor=lightgreen align=center>";
echo"<tr><th align=center>Item</th>
	<th align=center>Price</th>
	<th align=center>Quantity</th>
	<th align=center>Total</th>
	</tr>";

$gtotal = 0;
foreach($items as $item)
{
	$total = $item['Quantity'] * $item['Price'];//Count total for the Current Item
	$gtotal += $total; //Calculate the Grand Total
	echo"<tr><td align=center>{$item['Item']}</td>
	<td align=center>{$item['Price']}</td>
	<td align=center>{$item['Quantity']}</td>
	<td align=center>$total</td>
	</tr>";
}
echo"<tr><th colspan=3 align=left>Total</th><th>$gtotal</th> </tr>";
echo "</table>";

?>

تشكراتي لمرورك الطيب

بدون لا نستخدم لفحتي ولكن لا اريد استخدام foreach أنما اردي استخدام while مع each ولا نستخدم list

فقط اريد استخدام while مع each

#4
<?php
$items=array(
        	0=>array('Item'=>'Tea','Price'=>'1.250','Quantity'=>'3'),
        	1=>array('Item'=>'Coffee','Price'=>'2.5','Quantity'=>'5'),
        	2=>array('Item'=>'Rice','Price'=>'5','Quantity'=>'1')
	);
echo"<table border=3 width=400 bgcolor=lightgreen align=center>";
echo"<tr><th align=center>Item</th>
    	<th align=center>Price</th>
    	<th align=center>Quantity</th>
    	<th align=center>Total</th>
    	</tr>";

$gtotal = 0;
while($myarray=each($items))
{
    	$total = $myarray[1]['Quantity'] * $myarray[1]['Price'];//Count total for the Current Item
    	$gtotal += $total; //Calculate the Grand Total
    	echo"<tr><td align=center>{$myarray[1]['Item']}</td>
    	<td align=center>{$myarray[1]['Price']}</td>
    	<td align=center>{$myarray[1]['Quantity']}</td>
    	<td align=center>$total</td>
    	</tr>";
}
echo"<tr><th colspan=3 align=left>Total</th><th>$gtotal</th> </tr>";
echo "</table>";

?>
1

مواضيع مشابهة