PHP访问数组值 [英] PHP Accessing Array Value

查看:64
本文介绍了PHP访问数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问我创建的数组的值,但是它似乎失败了.

i am trying to access the value of an array that i have created, but it seems to fail.

我正在遍历发送VIA http的数组,并将 docno entryno 添加到名为 $ ArrID 的新数组中,它可以被添加到新数组中,但是当我尝试访问 ArrID 时,它似乎并没有从 array 本身获取任何信息,而我确信 ArrID 包含项目

I am looping through an array that sends VIA http, and adding the docno and entryno to new array called $ArrID, it can be added to the new array, however when i try to access the ArrID it seem to get nothing from the array itself while i am confident that ArrID contain the items

CODE

$ArrID = [];
foreach ($form_data_body as $key => $value) {
  $docno = $value -> doc_no;
  $entryno = $value -> entryno;
  if($mysqli->query($sql) == 1){
    $itemArr = array('docno' => $docno, 'entryno' => $entryno);
    $ArrID[] = $itemArr;
  }
}

if(count($ArrID)>0){
    foreach ($ArrID as $key => $values) {
      echo $values -> docno;
    }
}

推荐答案

您正在与 object array

请参见 http://php.net/manual/en/language.types.array.php http://php.net/manual/en/language.types.object.php

$ArrID = [];
foreach ($form_data_body as $key => $value) {
  $docno = $value['doc_no'];
  $entryno = $value['entryno'];
  if($mysqli->query($sql) == 1){
    $itemArr = array('docno' => $docno, 'entryno' => $entryno);
    $ArrID[] = $itemArr;
  }
}

if(count($ArrID)>0){
    foreach ($ArrID as $key => $values) {
      echo $values['docno'];
    }
}

这篇关于PHP访问数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆