Robert Cummings wrote:
On Wed, 2009-01-28 at 01:07 +0100, Edmund Hertle wrote:
2009/1/28 Terion Miller <webdev.terion@xxxxxxxxx>
I googled this and didn't find an answer ....
my question is how do you know when to use an object or array
would an object just be 1 instance, and array is several things together (
I
know infantile coder language I use..but I'm a baby still in this)
Can someone explain objects and arrays in plain speak for me?
Thanks
Happy Coding
Hey,
Arrays: A structure to store data
Example:
$example = array("value1", "value2", "value3);
echo $example[0]; // echos "value1"
echo $example[2]; // echos "value3"
Object: Something totally diffrent. A object is an instance of a class.
Contains variables and methods.
I don't know how you thought of using arrays or objects for the same
problem? Can you give an example?
An array's functionality can be implemented as a Class with specific
array instances being Objects. This allows the array to be used in
polymorphic contexts and to be extended by subclasses. The same can be
said for any primitive datatype.
Personally, I haven't seen a need to use an Array class in PHP. That's
not to say it doesn't have a purpose, but I lean towards primitives when
possible for efficiency.
Cheers,
Rob.
ahh i said the same until recently, and it's actually prompted me to
start making some generic container classes with array accessors.
simple example being, I want an array which can't have duplicates and
doesn't have any kind of ordered indexing, just an array or container i
can throw objects in and trust that i won't have any dups. Another
example is if you want an array of objects which can only be of
class/interface type xxxxx
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php