0

I'm creating this array:

 foreach($html->find('.position4') as $test) {
$aanvaller['naam']          = $test->find('.col1', 0)->plaintext;
$aanvaller['club']          = $test->find('.col2', 0)->plaintext;
$aanvaller['type']          = 'Aanvaller';
$aanvaller['wedstrijden']   = $test->find('.col3', 0)->plaintext;
$aanvaller['goals']         = $test->find('.col4', 0)->plaintext;
$aanvaller['punten']        = $test->find('.col5', 0)->plaintext; 
$aanvallers[] = $aanvaller;

}

When I use print_r($aanvallers) I get this:

 Array ( [0] => Array ( 
 [naam] => Catalin Tira 
 [club] => ADO 
 [type] => Aanvaller 
 [wedstrijden] => 0 
 [goals] => 0 
 [punten] => 0 )

and a lot more values. But the array is filled with the right values. Now I want to ready the values using this:

 for($i=0; $i<count($aanvallers); $i++){
    echo $aanvallers[$i]->naam;
 }

But when I use this, I don't get any values showed. So what am I doing wrong?

3
  • 4
    You are trying to use an object operator ->naam instead of an array key ['naam'] as in $aanvallers[$i]['naam']. Better would be foreach($aanvallers as $a) { echo $a['naam']; } Commented Sep 14, 2013 at 12:53
  • Thanks. Works now when changing it to ['naam']! Commented Sep 14, 2013 at 12:58
  • I guess that makes it answered. :-) Commented Sep 14, 2013 at 13:00

2 Answers 2

3

Don't use the inner array as an object. It's still an array too,

 for($i=0; $i<count($aanvallers); $i++){
    echo $aanvallers[$i]['naam'];
 }
Sign up to request clarification or add additional context in comments.

Comments

1
 for($i=0; $i<count($aanvallers); $i++){
    echo $aanvallers[$i]['naam'];
 }

It's array in array, so same addressing.

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.