我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

访问模型没有foreach

If its possible to access the 'entry_id' data in a foreach loop as below, if I know there is only one item, is there a better way to access it?

$arr = array();

foreach( $order->items as $item ) {
    $arr[] = $item->entry_id;
}

If order->items is no-associative array and its only 1 element, you can access it this way:

echo $order->items[0]->entry_id;

But more safe will be check how many items in array:

if(count($order->items) > 0)
    echo $order->items[0]->entry_id;

近期文章

  • 当两个发布请求到达服务器时,处理php中的重试发布请求
  • cookies php:无法使用isset()
  • 使用jQuery .ajax()有效地输出查询结果? [关闭]
  • 如何使用没有参数的spl_autoload_register?
  • 宁静的JSON Web服务:最好的方法吗?
  • 带选项的Datepicker选择几天[关闭]
  • 如何阻止FluentPDO错误地推断表名
  • 使用If Else语句通知结果AJAX的用户
  • Mod-Rewrite:使用QSA标志时忽略/排除参数
  • AJAX按查询排序[关闭]
  • 如何避免数据结果中的html代码
  • 如何在登录后重定向WordPress
  • 匹配直到正则表达式中的另一个表达式
  • PHP Foreach循环结束
  • PHP - 使用XML时解析错误
  • 如何在SilverStripe中使用模板中的参数调用函数
  • 更多结果 - 更快的查询(在mysql中按纬度和经度搜索)
  • php以JSON形式回显多维数组
  • 在Ajax调用之后显示成功消息的问题
  • 使用{PAGE_NUM}为页面编号时,make dompdf跳过第一页

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华