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)

link|improve this question

7% accept rate
As per comment of Michael on your other question: (1) Improve your acceptance rate by accepting the answers to your previous questions where appropriate. – RepWhoringPeeHaa Nov 4 '11 at 19:00
2  
@user979331: You should consider accepting answers to some of your previous questions. You'll be more likely to get helpful responses if people see you have a decent "accept rate" - yours is currently 0%. – Colin Nov 4 '11 at 19:00
feedback

3 Answers

You need to do

foreach($resultArrayy as $result){
    if array_key_exists('invoceid', $result)
        echo $result['invoiceid'] . "<br/>";
}
link|improve this answer
3  
He doesn't need another foreach loop, and if, he can directly get invoiceid inside first foreach. Check my answer. – yasar11732 Nov 4 '11 at 19:06
But yasar, O(N) is sooo boooorrriiiiinng. – Dereleased Nov 4 '11 at 19:10
@Dereleased I didn't get what you meant by (O)N , I am not a native speaker. – yasar11732 Nov 4 '11 at 19:16
I was just trying to make an example of other variation for the foreach loop – Reza Sanaie Nov 4 '11 at 19:17
1  
@yasar11732, this: en.wikipedia.org/wiki/Big_O_notation – Dereleased Nov 4 '11 at 19:27
feedback
foreach($resultarray as $result)
    echo $result["invoiceid"];
link|improve this answer
Really 3 upvotes? Nobody realized, that this doesn't work as expected? That may return invoiceid of the last entry only (when you use $resultArray) – KingCrunch Nov 4 '11 at 19:05
Won't work: notice the semicolon at the end of the foreach. – Levi Morrison Nov 4 '11 at 19:06
Technically it worked for the example given... just not broadly applicable. Semicolon removed. Today I am edit-king. – Dereleased Nov 4 '11 at 19:09
Sorry, I was tired after a long day, I must have been careless. Thanks @Derelased for fixing it. – yasar11732 Nov 4 '11 at 19:10
feedback
foreach($resultArray as $value){
    echo $value['invoiceid'] . "<br/>";
}
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.