1

I have the following output sing var_dump.. How do I read the value of 'transferfrom' for each array ? The 'ST00576' and 'OT01606' are dynamic values.It can change on the subsequence arrays.

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)

  }
}
1
  • Maybe I'm not understanding your question, but don't you just need a foreach loop? Commented Jul 2, 2012 at 2:30

2 Answers 2

2

Not sure exactly what you need, but this will pick the 'transferfrom' item out of each array entry and return an array with the same keys but strings as values.

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

Or:

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

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

Result (shortened):

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

Or you can just iterate:

foreach ($arr as $key => $item) {
    $transferfrom = $item->transferfrom;
    // do whatever you like with $transferfrom and $key
}
Sign up to request clarification or add additional context in comments.

Comments

0
foreach($arrays as $arr){
  $transferfrom = $arr['transferfrom'];
  //here you do whatever you want with $arr
  //...
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.