php - 尝试访问 int 类型值的数组偏移量 - 对于每个循环
问题描述
所以在我的代码中,我有 2 个函数。一种将返回表中的所有行,另一种将根据其返回 1 行code
。
当我运行该函数以获取所有这些函数时 - 没有问题 - 使用foreach
循环可以正常工作并显示在 html 上。
但是,当我运行该函数以获取一个函数时,我在引用数组的每一行的标题中出现错误,例如$location['address_line2']
。
我知道这是较新版本的 php 的错误,但找不到解决方法。
顺便说一句,查询工作正常,我用来print_r
在 foreach 循环之前显示它,我可以在检查元素中看到它。
$premises = getPremisesByCode($connection, $premisesCode);
//$premises = getAllPremises($connection);
if($premises != NULL){
foreach ($premises as $location) {
$visible = ($location['active'] != 'deactivated' ? '<span class="fa-stack"><i style="color: #008d1b;" class="fa fa-check fa-stack-1x"></i></span>' : '<span class="fa-stack"><i style="color: #8d0000;" class="fa fa-times fa-stack-1x"></i></span>' );
$editBtn = '<a class="btn btn-xs btn-info px-2 py-1 shadow" href="/'.$productfolder.'/edit-product-type/'.$location['code'].'/" title="Edit this product"><i style="font-size: 1rem;" class="mdi mdi-lead-pencil"></i></a> ';
$toggleIcon = ($location['active'] != 'deactivated') ? '<i class="mdi mdi-close"></i>' : '<i class="mdi mdi-check"></i>';
$toggleColour = ($location['active'] != 'deactivated') ? 'warning' : 'success';
$toggleBtn = '<a class="btn btn-xs btn-'.$toggleColour.' px-2 py-1 shadow" href="/'.$productfolder.'/toggle-premises/'.$location['code'].'/">'.$toggleIcon.'</a> ';
$ptImage = (isset($location['logo'])) ? '<img class="img-thumbnail shadow mx-auto d-block p-2" style="max-width: 200px; background-color: '.$location['primary_colour'].' " src="/assets/images/'.$location['logo'].'">' : '<strong>No Image Uploaded!</strong>';
$locationAddress = $location['address_line1'].'<br>';
$locationAddress .= ($location['address_line2'] != '') ? $location['address_line2'].'<br>' : NULL;
$locationAddress .= ($location['address_city'] != '') ? $location['address_city'].'<br>': NULL;
$locationAddress .= $location['address_county'].'<br>';
$locationAddress .= $location['address_postal_code'].'<br>';
$outputTr .= '
<tr id="'.$location['id'].'">
<td width="100px">'.$editBtn.$toggleBtn.'</td>
<td>'.$ptImage.'</td>
<td>'.$location['name'].'</td>
<td>'.$locationAddress.$premisesCode.'</td>
<td>'.$visible.'</td>
</tr>';
}
解决方案
推荐阅读
- c# - 将 Identity Server 与单独的 api 一起使用
- react-redux - 未调用 mapStateToProps 时如何处理这种 Redux Store 场景
- ios - 按 @ 时包括电话号码和显示名称
- c - C Array 创建木马?
- java - 如何从 firebase 检索图像和文本到回收视图?
- javascript - JavaScript 转置数据
- android - RxJava observeOn / subscribeOn 仅在测试环境中有效
- javascript - 在有多个条目的Webpack v4中,我的splitChunks没有优化,如果我的两个页面包含core-js,它们都会得到一个副本
- javascript - 用带条件的数字升序填充数组
- jquery - 我正在使用 Jquery 添加一个 src 属性,但它的工作方式不同。为什么?