php - 试图在选择中获取邮件诗人列表
问题描述
我正在尝试使用下面的代码在下拉列表中获取邮件诗人列表,但我只获得选项中的第一个值和 id,尽管有 5 个列表可用,我做错了什么?
$mplistname = array(\MailPoet\API\API::MP('v1')->getLists()[0]['name']);
$mplistid = array(\MailPoet\API\API::MP('v1')->getLists()[0]['id']);
$mplistoptions = array_combine($mplistid, $mplistname);
foreach($mplistoptions as $key=>$value) {
$mplistoptions[$key] = $value;
}
解决方案
正如 Patryk 所说,当一个就足够时,不要进行两次 API 调用。
你只得到名字和id,因为你只访问两个数组中的第一个条目……就是[0]
这样。
这可能应该被浓缩成这样的东西:
$data = \MailPoet\API\API::MP('v1')->getLists();
foreach($data as $record) {
// do stuff with $record['name'] and $record['id'] here
}
推荐阅读
- java - elasticsearch 6 ESIntegTestCase“代码库属性已设置”
- random - 使用 Wolfram Mathematica 获得分布的示例模拟
- r - R导入多个csv文件
- python - 如何在列表中对具有相同键的字典值求和?
- ios - layoutSubviews 添加到 UICollectionView 时冻结应用程序
- mysql - Mysql生成查询以生成自定义结果
- c# - 即使 MessageVersion 是 Soap11WSAddressing10,WCF 仍在使用 SOAP 1.2
- c# - 如何将格式化的文本从 Windows 窗体传递到 Word 应用程序?
- fiware - 如何使用 Wirecloud sth-source 算子
- python-3.x - 在 python 中使用 pymssql 从 SQL Server 检索数据正在用 False 替换 0,用 None 替换 NULL