Php循环$a=新发货包(';UPS';);
下面的代码需要一个PHP循环:生成下面示例的最简单方法是什么Php循环$a=新发货包(';UPS';);,php,Php,下面的代码需要一个PHP循环:生成下面示例的最简单方法是什么 $a = new ShipPackage('UPS'); $a->setParameter('length','5'); $a->setParameter('width','5'); $a->setParameter('height','5'); $a->setParameter('weight','5'); $combined->addPackageToShipment($a); 如果循环3X,则应
$a = new ShipPackage('UPS');
$a->setParameter('length','5');
$a->setParameter('width','5');
$a->setParameter('height','5');
$a->setParameter('weight','5');
$combined->addPackageToShipment($a);
如果循环3X,则应如下所示:
$a = new ShipPackage('UPS');
$a->setParameter('length','5');
$a->setParameter('width','5');
$a->setParameter('height','5');
$a->setParameter('weight','5');
$combined->addPackageToShipment($a);
$a2 = new ShipPackage('UPS');
$a2->setParameter('length','5');
$a2->setParameter('width','5');
$a2->setParameter('height','5');
$a2->setParameter('weight','5');
$combined->addPackageToShipment($a2);
$a3 = new ShipPackage('UPS');
$a3->setParameter('length','5');
$a3->setParameter('width','5');
$a3->setParameter('height','5');
$a3->setParameter('weight','5');
$combined->addPackageToShipment($a3);
($x=0;$x<3;$x++)的
{
$a=新装运包(“UPS”);
$a->setParameter('length','5');
$a->setParameter('width','5');
$a->setParameter('height','5');
$a->setParameter('weight','5');
$combled->addPackageToShipment($a);
}
我不确定你的问题,但就我的理解而言,这是可行的。你可以使用
for
循环,根据需要多次循环代码。您没有提供任何关于为什么需要循环的信息,因此我假设for
循环是最好的
for ($b = 0; $b < 3; $b++) {
$a = new ShipPackage('UPS');
$a->setParameter('length','5');
$a->setParameter('width','5');
$a->setParameter('height','5');
$a->setParameter('weight','5');
$combined->addPackageToShipment($a);
}
看来你应该在这个问题上再努力一点,或者至少先在别处寻找答案。吉米·索马斯特是对的。你必须精通循环、数据类型等语言基础知识。。
for ($b = 0; $b < 3; $b++) {
$a = new ShipPackage('UPS');
$a->setParameter('length','5');
$a->setParameter('width','5');
$a->setParameter('height','5');
$a->setParameter('weight','5');
$combined->addPackageToShipment($a);
}
while ($canShip) {
$a = new ShipPackage('UPS');
$a->setParameter('length','5');
$a->setParameter('width','5');
$a->setParameter('height','5');
$a->setParameter('weight','5');
$combined->addPackageToShipment($a);
}