Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Array and ArrayObject

which one should be used to manipulating data, Array or Array Object? Like search,sort and other array manipulations.

like image 707
Imrul Avatar asked Sep 09 '09 15:09

Imrul


People also ask

What is ArrayObject PHP?

ArrayObject Flags ¶Properties of the object have their normal functionality when accessed as list (var_dump, foreach, etc.). ArrayObject::ARRAY_AS_PROPS. Entries can be accessed as properties (read and write).

How do you handle an array object in PHP?

Converting an object to an array with typecasting technique: php class bag { public function __construct( $item1, $item2, $item3){ $this->item1 = $item1; $this->item2 =$item2; $this->item3 = $item3; } } $myBag = new bag("Books", "Ball", "Pens"); echo "Before conversion :".

What does array [] mean in PHP?

An array is a data structure that stores one or more similar type of values in a single value. For example if you want to store 100 numbers then instead of defining 100 variables its easy to define an array of 100 length.


1 Answers

The basic type is array. This is a map of keys and values that can be written to, read from and accessed in a loop.

The ArrayObject is a class that you can extend to create objects that behave as if they were arrays. It implements methods like count and sort that enable you to treat an object like you would treat an array. It's part of the SPL (Standard PHP Library).

Typically you'd use array. You'll know when you need ArrayObject.

like image 163
drewm Avatar answered Sep 21 '22 12:09

drewm