Simple PHP question
I want to be able to randomly select the following from an array:
1). An image
2). A piece of text (name of tge image)
3). A piece of text (description of the image)
I want to be able to build a static array with the values hardcoded into
the array, and then be able to randomly select an item from the array
and retrieve the image, name and description.
I am new to PHP, but have been programming C/C++ for over 10 years.
In C++ it would look something like this:
class ImageInfo
{
public:
ImageInfo(const std::string& path, const std::string& name, const
std::string& descr);
ImageInfo(const ImageInfo&);
~ImageInfo();
std::string PathName() const ;
std::string Name() const ;
std::string Description() const ;
private:
std::string m_path, m_name, m_descr;
}
static std::vector<ImageInfo> theArray ;
static const ImageInfo& getRandomImageInfo()
{
//generate a random number less than number of items in vector
size_t index = random_index(theArray.size());
return theArray[index];
}
I need to know how to translate this into PHP. I know PHP does not have
the equivalent of the STL, so I will have to use use arrays instead. Any
help will be much appreciated.
|