$articles['Article'] = array('some string key' );
array_push($articles[get_class($tempObject)], $tempObject);
$object_name = get_class($object);
$articles[$object_name] = $object;
I do not know where array_push() fits into the equation ;-)
class Article {
public $title;
public $author;
public $pubdate;
public $description;
public $url;
public function __construct($title, $author, $pubdate, $description, $url)
{
$this->title = $title;
$this->author = $author;
$this->pubdate = $pubdate;
$this->description = $description;
$this->url = $url;
}
}
?>
return array(
"Jungle Book" => new Book("Jungle Book", "R. Kipling", "A classic book."),
"Moonwalker" => new Book("Moonwalker", "J. Walker", ""),
"PHP for Dummies" => new Book("PHP for Dummies", "Some Smart Guy", "")
);
you show your -
$articles['Article']
as being set to an array with One string in it, and in your "assign the string key" question you have it with - $tempObject you do Not say, but from the name it is an Object, not a string. What is it you need to do, How do we know how to make - $tempObject - a string, if we do not know what Object it is? Or what you may need in the -
$articles['myClass'] array sub array ??