Php imagejpeg在for循环中不工作
我在变量中有一个数组:Php imagejpeg在for循环中不工作,php,arrays,image,Php,Arrays,Image,我在变量中有一个数组: $fected_data 当我打印阵列时,我得到: Array ( [0] => Array ( [id] => 1 [zip] => 47006 [route] => C001 [no_mail] => 449 [type] => Residential [date_time] => abc ) [1] =&g
$fected_data
当我打印阵列时,我得到:
Array
(
[0] => Array
(
[id] => 1
[zip] => 47006
[route] => C001
[no_mail] => 449
[type] => Residential
[date_time] => abc
)
[1] => Array
(
[id] => 2
[zip] => 47006
[route] => C002
[no_mail] => 677
[type] => Residential
[date_time] =>
)
[2] => Array
(
[id] => 3
[zip] => 47006
[route] => H061
[no_mail] => 9
[type] => Residential
[date_time] =>
)
[3] => Array
(
[id] => 4
[zip] => 47006
[route] => R001
[no_mail] => 449
[type] => Residential
[date_time] =>
)
[4] => Array
(
[id] => 5
[zip] => 47006
[route] => R002
[no_mail] => 566
[type] => Residential
[date_time] =>
)
[5] => Array
(
[id] => 6
[zip] => 47006
[route] => R003
[no_mail] => 513
[type] => Residential
[date_time] =>
)
[6] => Array
(
[id] => 7
[zip] => 47006
[route] => R004
[no_mail] => 536
[type] => Residential
[date_time] =>
)
[7] => Array
(
[id] => 8
[zip] => 47006
[route] => R006
[no_mail] => 479
[type] => Residential
[date_time] =>
)
[8] => Array
(
[id] => 9
[zip] => 47006
[route] => R007
[no_mail] => 637
[type] => Residential
[date_time] =>
)
[9] => Array
(
[id] => 10
[zip] => 47037
[route] => R002
[no_mail] => 510
[type] => Residential
[date_time] =>
)
[10] => Array
(
[id] => 11
[zip] => 47006
[route] => R005
[no_mail] => 474
[type] => Residential
[date_time] =>
)
[11] => Array
(
[id] => 12
[zip] => 62812
[route] => C001
[no_mail] => 504
[type] => Residential
[date_time] =>
)
[12] => Array
(
[id] => 13
[zip] => 62812
[route] => C002
[no_mail] => 470
[type] => Residential
[date_time] =>
)
[13] => Array
(
[id] => 14
[zip] => 62812
[route] => C003
[no_mail] => 366
[type] => Residential
[date_time] =>
)
[14] => Array
(
[id] => 15
[zip] => 62812
[route] => C005
[no_mail] => 429
[type] => Residential
[date_time] =>
)
现在基于这个数组,我需要在一些信使纸条上写,通过数组值循环,我需要把负责写文本的代码放在一个嵌套的for循环中,放在foreach中,所以对于第一个图像,它工作正常,但看不到其他图像,逻辑在我这方面似乎很好,但我认为imagejpeg在循环中不起作用。请帮帮我
foreach($fected_data as $fected)
{
$no_of_mailp = $fected['no_mail'];
$devided_number = bcdiv($fected['no_mail'], 100, 2).'<br>';
$totalboxes = explode('.' , $devided_number);
$totalbundles = $totalboxes['0']+1;
$zipcode = $fected['zip'];
$route = $fected['route'];
$type = $fected['type'];
for($i=0;$i < $totalbundles;$i++)
{
echo $extended_var = $i+1;
if($extended_var != $totalbundles)
{
header('Content-type: image/jpeg');
$jpg_image = imagecreatefromjpeg('faceslip.jpg');
$white = imagecolorallocate($jpg_image, 0, 0, 0);
$font_path = 'arial.ttf';
$total_mail_pc = 100;
// zipcode
$x=150;
for($i=0;$i<=strlen($zipcode);$i++){
$print_text=substr($zipcode,$i,1);
$x+=35;
imagettftext($jpg_image, 50, 0, $x, 570, $white, $font_path, $print_text);
}
// Route
$x=350;
for($i=0;$i<=strlen($route);$i++){
$route_text=substr($route,$i,1);
$x+=35;
imagettftext($jpg_image, 50, 0, $x, 570, $white, $font_path, $route_text);
}
// Type
$x=650;
for($i=0;$i<=strlen($type);$i++){
$type_text=substr($type,$i,1);
$x+=35;
imagettftext($jpg_image, 50, 0, $x, 570, $white, $font_path, $type_text);
}
// No of mp
$x=350;
for($i=0;$i<=strlen($total_mail_pc);$i++){
$total_mail_pc_text=substr($total_mail_pc,$i,1);
$x+=35;
imagettftext($jpg_image, 50, 0, $x, 870, $white, $font_path, $total_mail_pc_text);
}
// page of page
$x=600;
for($i=0;$i<=strlen($extended_var);$i++){
$extended_var_text=substr($extended_var,$i,1);
$x+=35;
imagettftext($jpg_image, 50, 0, $x, 1000, $white, $font_path, $extended_var_text);
}
// page of page
$x=700;
for($i=0;$i<=strlen($totalbundles);$i++){
$totalbundles_text=substr($totalbundles,$i,1);
$x+=35;
imagettftext($jpg_image, 50, 0, $x, 1000, $white, $font_path, $totalbundles_text);
}
// Send Image to Browser
$nameoffile = $zipcode.'-'.$route.'-'.$extended_var.'.jpg';
imagejpeg($jpg_image, $nameoffile);
// Clear Memory
imagedestroy($jpg_image);
}
else {
$total_mail_pc = $totalboxes[1];
}
}
}
foreach($infected_数据为$infected)
{
$no_of_mailp=$infected['no_mail'];
$devided_number=bcdiv($infected['no_mail'],100,2)。“
”;
$TotalBox=分解('.',$devided_编号);
$totalbundles=$TotalBox['0']+1;
$zipcode=$infected['zip'];
$route=$infected['route'];
$type=$infected['type'];
对于($i=0;$i<$totalbundles;$i++)
{
echo$extended_var=$i+1;
如果($extended_var!=$totalbundles)
{
标题(“内容类型:图像/jpeg”);
$jpg_image=imagecreatefromjpeg('faceslip.jpg');
$white=imagecolorallocate($jpg_图像,0,0,0);
$font_path='arial.ttf';
$total_mail_pc=100;
//zipcode
$x=150;
对于($i=0;$iI)来说,我想这是因为您在循环中的另一个循环($i
)使用了相同的变量名,这使得值“$i”已经位于循环的末尾,使第一个循环停止。@cwps太好了,我只是粗心了,在半夜工作。您救了我的命:)哈哈,我可以在哪里给您送啤酒?