php - FPDF 页脚获取在 foreach 行上声明的变量
问题描述
我声明了一个名为“$shop”的变量,如下所示:
foreach($shop_list as $shop)
function_that_writes_pdf_files($shop);
我想在我的页脚中使用 $shop 。可能吗 ?我可以通过使用来使用变量
global $variable
但它不适用于 $shop 如果您有答案或在某处看到答案,请分享
解决方案
当您使用自己的名称扩展 fPDF 类时创建一个小函数。该函数只是设置一个公共变量,该变量保存$shop
您可以在页脚函数中使用的值。
class my_pdf extends FPDF {
public $shop;
public function setshop($input) {$this->shop = $input;}
function Footer() {
$this->Cell(15,5,$this->shop,0,0,'L'); // Using the value of shop here
} // end of the Footer function
}
$ourpdf = new my_pdf('P','mm','Letter');
foreach($shop_list as $shop) {
$ourpdf->setshop($shop); // This sets the value of $shop to the fPDF class you created so the footer function may use it
function_that_writes_pdf_files($shop);
}
推荐阅读
- ios - 将 Codable 保存到 UserDefaults 并匹配 NSCoding 的外观
- android - 是否可以有两种文本颜色的单个文本视图?
- jquery - 如何使用 multer(或其他)使用 jquery ajax 在 Nodejs 中上传文件?
- python-3.x - 当 ECOS 无法使用约 25,000 个优化变量解决我的 SOCP 时,这意味着什么?
- python - 如何在 Cython 中使用不同的 C++ 编译器?
- c++ - 奇怪的班级演员发生
- express - 如何防止在 API 端点服务器端多次点击?
- c# - 发送数据时,模型中的布尔字段未在控制器中更新
- c# - 将子域映射到 ASP.Net Core 3 中的区域
- iis-7.5 - 内部 II(S) 网站适用于 HTTP(S),但不适用于 HTTP