function - 获取数组中返回的另一个文件中的函数值
问题描述
我在一个文件中有一个函数,它通知数组中的值,但我需要在另一个文件中获取这些值。
我正在使用magento,需要从具有发出请求的客户端名称的函数中获取信息,我试图获取first_name,但它没有用。
文件一.php
public function getCustomerInfo($customer, $order)
{
$email = htmlentities($customer->getEmail());
if ($email == "") {
$email = $order['customer_email'];
}
$first_name = htmlentities($customer->getFirstname());
if ($first_name == "") {
$first_name = $order->getBillingAddress()->getFirstname();
}
$last_name = htmlentities($customer->getLastname());
if ($last_name == "") {
$last_name = $order->getBillingAddress()->getLastname();
}
return array('email' => $email, 'first_name' => $first_name, 'last_name' => $last_name);
}
文件二.php
require(../Model/fileone.php
public function getName(){
$name = $this->getCustomerInfo($customer, $order);
$first_name = $name['first_name'];
return $first_name;
}
我需要显示 first_name 中的客户端名称,但未显示。
解决方案
您有两个文件,一个具有您想从另一个调用的功能。
要使用getCustomerInfo()
另一个文件中的函数,您需要导入包含该函数的类(使用use
or require_once()
)。
如果您导入其他文件,则在函数调用之前不会使用this->
该函数,因为该getCustomerInfo()
函数与该函数不属于同一类getName()
。
由于在您提供的示例中,这些函数不是类的一部分,因此您应该能够require_once(fileOne.php);
在 fileTwo.php 的顶部以及getCustomerInfo()
该文件中的任何位置调用。
根据函数的声明,调用getCustomerInfo()
它时需要有两个参数。
推荐阅读
- android - 屏幕关闭时,quickblox 示例视频聊天未接听电话
- c# - 导航到已在 Backstack 中查看
- google-sheets - 如何使用 ARRAYFORMULA 处理数组数组
- javascript - 组件自动完成 VueJS
- javascript - 单击链接时关闭全屏导航覆盖
- java - Junit 测试运行冻结
- scala - 检查文件路径扩展是否存在逻辑。斯卡拉
- php - Curl POST 上传文件请求返回 false
- ruby-on-rails - Rails:嵌套关联的复杂查询
- html - 如何使用 Icon Font 使 Material Icons 圆润?