Урок - ArrayObject

Главная » Курсы » Курс ACMF » Урок - ArrayObject

Обучающий онлайн курс
ACMF

Лицензия: Лицензия Creative Commons.

Properties

  • ArrayObject::length - contains the number of elements in the array.

Methods

  • ArrayObject::clear() - clears ArrayObject and returns this.
  • ArrayObject::clone() - clones ArrayObject.
  • ArrayObject::count() - returns items count in ArrayObject.
  • ArrayObject::cut(Position[, Count = 1):ArrayObject - deletes elements by position (and count) and returns them as ArrayObject.
  • ArrayObject::delete(Position[, Count = 1):this - deletes element by position number (and count) and return this.
  • ArrayObject::first() - returns first element from ArrayObject without removing.
  • ArrayObject::get(Position) - returns value by position number from ArrayObject without removing.
  • ArrayObject::has(Position) - returns true if element with position number exists.
  • ArrayObject::keys() - returns keys as ArrayObject.
  • ArrayObject::last() - returns last element from ArrayObject without removing.
  • ArrayObject::lead(Mixed) - inserts element at the begin.
  • ArrayObject::map(Callback[, args]) - apply callback function to each element.
  • ArrayObject::pop():Mixed - returns last element and remove it.
  • ArrayObject::push(Mixed) - inserts element at the end.
  • ArrayObject::remove(Position[, Default]):Mixed - deletes element by position and returns it.
  • ArrayObject::set(Position, Mixed) - update element by position number.
  • ArrayObject::turn(Default):Mixed - removes first element and returns it.
  • ArrayObject::toPHPArray() - returns array as PHP Array.
  • ArrayObject::values() - returns values.

Examples

Delete first element.

Using Array.turn() method:

el = a.turn()
el = a.turn(default)

Using Array.delete() method:

a.delete(1)

Using Array.remove() method:

el = a.remove(1)
el = a.remove(1, default)

Delete last element.

Using Array.pop() method:

el = a.pop()
el = a.pop(default)

Using Array.delete() method:

a.delete(a.length)
a.delete(-1)

Using Array.remove() method:

el = a.remove(a.length)
el = a.remove(a.length, default)
el = a.remove(-1)
el = a.remove(-1, default) 

Delete any element.

Using Array.delete() method:

a.delete(2)

Using Array.remove() method:

el = a.remove(3)
el = a.remove(4, default)

Delete a few elements.

Using Array.delete() method:

a.delete(2, 5)

Using Array.cut() method:

a.cut(2, 5)