• PHP Video Tutorials

PHP - Sequence Functions


Advertisements

Introduction to Sequence interface

A Sequence can describe the behavior of values arranged in a single, linear dimension. Some languages can refer to this as a List. It is similar to an array that uses incremental integer keys, with the exception of a few characteristics.

  • Values can always be indexed as [0, 1, 2, …, size - 1].
  • Only allowed to access values by index in the range [0, size - 1].

Use cases

  • Wherever we can use an array as a list (not concerned with keys).
  • A more efficient alternative to SplDoublyLinkedList and SplFixedArray.

Interface synopsis

Ds\Sequence implements Ds\Collection {
   /* Methods */
   abstract public void allocate( int $capacity )
   abstract public void apply( callable $callback )
   abstract public int capacity( void ) 
   abstract public bool contains([ mixed $...values ] )
   abstract public Ds\Sequence filter([ callable $callback ] )
   abstract public mixed find( mixed $value )
   abstract public mixed first( void )
   abstract public mixed get( int $index )
   abstract public void insert( int $index [, mixed $...values ] )
   abstract public string join([ string $glue ] )
   abstract public mixed last( void )
   abstract public Ds\Sequence map( callable $callback )
   abstract public Ds\Sequence merge( mixed $values )
   abstract public mixed pop( void )
   abstract public void push([ mixed $...values ] )
   abstract public mixed reduce( callable $callback [, mixed $initial ] )
   abstract public mixed remove( int $index )
   abstract public void reverse( void )
   abstract public Ds\Sequence reversed( void )
   abstract public void rotate( int $rotations )
   abstract public void set( int $index , mixed $value )
   abstract public mixed shift( void )
   abstract public Ds\Sequence slice( int $index [, int $length ] )
   abstract public void sort([ callable $comparator ] )
   abstract public Ds\Sequence sorted([ callable $comparator ] )
   abstract public number sum( void )
   abstract public void unshift([ mixed $values ] )
}

Predefined Constants

Ds\Map::MIN_CAPACITY

Sr.No Function & Description
1

Ds\Sequence::allocate()

This Function can allocate enough memory for a required capacity.

2

Ds\Sequence::apply()

This Function can update all values by applying a callback function to each value.

3

Ds\Sequence::capacity()

This Function can return the current capacity.

4

Ds\Sequence::contains()

This Function can determine if a sequence contains given values.

5

Ds\Sequence::filter()

create a new sequence using callable to determine which values to include.

6

Ds\Sequence::find()

This Function can attempt to find the value's index.

7

Ds\Sequence::first()

This Function can can return the first value in a sequence..

8

Ds\Sequence::get()

This Function can return the value at a given index.

9

Ds\Sequence::insert()

This Function can insert values at a given index.

10

Ds\Sequence::join()

This Function can join all values together as a string.

11

Ds\Sequence::last()

This Function can return the last value.

12

Ds\Sequence::map()

This Function can return the result of applying a callback to each value.

13

Ds\Sequence::merge()

This Function can return the result of adding all given values to the sequence.

14

Ds\Sequence::pop()

This Function can remove and return the last value.

15

Ds\Sequence::push()

This Function can add values to the end of a sequence.

16

Ds\Sequence::reduce()

This Function can reduce the sequence to a single value using a callback function.

17

Ds\Sequence::remove()

This Function can remove and return a value by index.

18

Ds\Sequence::reverse()

This Function can can reverse a sequence in-place.

19

Ds\Sequence::reversed()

This Function can return a reversed copy.

20

Ds\Sequence::rotate()

This Function can rotate the sequence by given number of rotations.

21

Ds\Sequence::set()

This Function can update a value at the given index.

22

Ds\Sequence::shift()

This Function can remove and return a first value.

23

Ds\Sequence::slice()

This Function can return a sub-sequence of the given range.

24

Ds\Sequence::sort()

This Function can sort a sequence in-place.

25

Ds\Sequence::sorted()

This Function can return a sorted copy.

26

Ds\Sequence::sum()

This Function can return the sum of all values in a sequence.

27

Ds\Sequence::unshift()

This Function add values to the front of a sequence.

php_function_reference.htm

Useful Video Courses


Video

PHP Online Training

45 Lectures 9 hours

Malhar Lathkar

Video

Become PHP Facebook Developer: Password-Less Authentication

34 Lectures 4 hours

Syed Raza

Video

Ultimate PHP & MySQL Web Development Course & OOP Coding

84 Lectures 5.5 hours

Frahaan Hussain

Video

Learn PHP from Scratch

17 Lectures 1 hours

Nivedita Jain

Video

E Commerce Website Development In PHP With PDO

100 Lectures 34 hours

Azaz Patel

Video

PHP in Telugu

43 Lectures 5.5 hours

Vijay Kumar Parvatha Reddy

Advertisements