I have a weird issue with a foreach loop and references. Here is my code:
$authors = array(
new Author(array('first_name'=>'Name 1','last_name'=>'last name 1')),
new Author(array('first_name'=>'name 1','last_name'=>'last name 2')),
);
foreach($authors as $key => $author){
$authors[$key] = Author::manager()->getOrCreate($author);
print $author->id."-".$authors[0]->id."<br>";
}
So if we assume that both of those objects are created in the database, then the output shown is :
1-1
2-2
As you guess my question is: why does $authors[0]->id refers to $author->id ??
I suppose that it is a problem with reference but since I don't use reference in the foreach loop, I have no idea where it comes from!
Any suggestion will be welcome. Thanks