user979331
user979331

Reputation: 11851

Get the values from one column a 2d array

I have this array and I did a print_r($resultArray) and got these results;

Array ( [0] => Array ( [invoiceid] => 992 [client] => www [invoicedeliverymethod] => email [date] => 2011-11-04 [enddate] => 2011-10-31 23:59:59 [total] => 103.00 [remainingbalance] => 103.00 [ispaid] => No [isagentpaid] => No [datedistributed] => 2011-11-04 [invoicedcontact] => 1 ) [1] => Array ( [invoiceid] => 991 [client] => www [invoicedeliverymethod] => email [date] => 2011-11-04 [enddate] => 2011-09-30 23:59:59 [total] => 103.00 [remainingbalance] => 103.00 [ispaid] => No [isagentpaid] => No [datedistributed] => Not distributed [invoicedcontact] => 1 ) [2] => Array ( [invoiceid] => 988 [client] => Sylvester Services [invoicedeliverymethod] => email [date] => 2011-11-04 [enddate] => 2011-10-31 23:59:59 [total] => 16687.83 [remainingbalance] => -16487.83 [ispaid] => No [isagentpaid] => No [datedistributed] => Not distributed [invoicedcontact] => 1 ) [3] => Array ( [invoiceid] => 987 [client] => Colony Holland Lumber [invoicedeliverymethod] => email [date] => 2011-11-04 [enddate] => 2011-10-31 23:59:59 [total] => 8345.39 [remainingbalance] => -8245.39 [ispaid] => No [isagentpaid] => No [datedistributed] => Not distributed [invoicedcontact] => 1 ) )

What I am trying to do it write a foreach loop that gets each one of the [invoiceid]

This is what I have so far

    foreach($resultArrayy as $key){
    foreach($key as $value){
        echo $value . "<br/>";
    }
}

But that returns this;

992
www
email
2011-11-04
2011-10-31 23:59:59
103.00
103.00
No
No
2011-11-04
1

for each one (but different data)

Upvotes: 0

Views: 155

Answers (3)

Reza S
Reza S

Reputation: 9748

You need to do

foreach($resultArrayy as $result){
    if array_key_exists('invoceid', $result)
        echo $result['invoiceid'] . "<br/>";
}

Upvotes: 0

yasar
yasar

Reputation: 13738

foreach($resultarray as $result)
    echo $result["invoiceid"];

Upvotes: 0

KingCrunch
KingCrunch

Reputation: 131861

foreach($resultArray as $value){
    echo $value['invoiceid'] . "<br/>";
}

Upvotes: 5

Related Questions