1

我有以下输出 sing var_dump .. 如何读取每个数组的“transferfrom”值?'ST00576' 和 'OT01606' 是动态值。它可以在子序列数组上改变。

string(19) "TB3360    7D  B  70"
array(2) {
  ["ST00576"]=>
  object(stdClass)#1 (13) {
    ["transferfrom"]=>
    int(102)
    ["transferto"]=>
    int(66)
    ["BR_ID"]=>
    int(102)

  }
  ["OT01606"]=>
  object(stdClass)#2 (13) {
    ["transferfrom"]=>
    int(102)
    ["transferto"]=>
    int(66)
    ["BR_ID"]=>
    int(66)

  }
}

string(19) "TB3360    BL  A  75"
array(2) {
  ["ST00576"]=>
  object(stdClass)#3 (13) {
    ["transferfrom"]=>
    int(102)
    ["transferto"]=>
    int(66)
    ["BR_ID"]=>
    int(102)

  }
  ["OT01606"]=>
  object(stdClass)#4 (13) {
    ["transferfrom"]=>
    int(102)
    ["transferto"]=>
    int(66)
    ["BR_ID"]=>
    int(66)

  }
}
4

2 回答 2

2

不确定您到底需要什么,但这将从'transferfrom'每个数组条目中挑选项目并返回一个具有相同键但字符串作为值的数组。

$arr = array_map(function($item) {
    return $item->transferfrom;
}, $arr);

或者:

function pick_transferfrom($item)
{
    return $item->transferfrom;
}

$arr = array_map('pick_transferfrom', $arr);

结果(缩短):

['OT01606' => 102, 'ST00576' => 102];

或者你可以迭代:

foreach ($arr as $key => $item) {
    $transferfrom = $item->transferfrom;
    // do whatever you like with $transferfrom and $key
}
于 2012-07-02T02:36:06.420 回答
0
foreach($arrays as $arr){
  $transferfrom = $arr['transferfrom'];
  //here you do whatever you want with $arr
  //...
}
于 2012-07-02T02:33:00.807 回答