Jump to content

[SOLVED] 2 objects of the same class


cssniper

Recommended Posts

Absolutely.  Consider the trivial example below.

 

<?php
class Book
{
  var $author, $title;
  function Book($author, $title)
  {
     $this->author = $author;
     $this->title = $title;
  }
  function getAuthor(){ return $this->author; }
  function getTitle(){ return $this->title; }
}

// ...

$books = array();
$books[] = new Book("some guy", "some book");
$booker[] = new Book("some other guy", "some other book");

foreach($books as $book){
  $book->getTitle() . ' by ' . $book->getAuthor(); . '<br />';
}
?>

 

Best,

 

Patrick

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.