Tuesday, 27 February 2018

Array in PHP

Array in PHP

A map is a kind that identify values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible.An array in PHP is actually an ordered map. A map is a kind that identify utility to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible. An array is a special variable, which can hold more than one value at a time. It is a data format that stock one or more codes in a separate code.An array in PHP is really an order map.It associates values to key.

Traditionally an array is considered to be a collection of homogeneous elements , which means that it can not contain dissimilar elements.
Array in PHP
Now we discuss the types of Array with the PHP Training in Chandigarh :

Types of Array in PHP: 

Indexed Array :

An indexed or numeric array stores each array element with a numeric index. Key of indexed array is integer starts with 0.It is used when we identify things from their position.

Associative Array :

In an associative array, the keys assigned to values can be arbitrary and user defined strings.It have
strings as keys and behave more like two-columns table.

PHP Training in Chandigarh

Multidimensional Array :

The multidimensional array is an array in which each element can also be an array and each element in the sub-array can be an array or further contain array within itself and so on.

Useful functions for manipulating array in PHP :

sizeof($arr) : This function returns the number of elements in an array.Use this function to find out how many elements an array contains; this information is most commonly used to initialize a loop counter when processing the array.
array_values($arr) : This function accepts a PHP array and returns a new array containing only its values (not its keys). Its counterpart is the array_keys() function.
Use this function to retrieve all the values from an associative array.
array_keys($arr) : This function accepts a PHP array and returns a new array containing only its keys (not its values). Its counterpart is the array_values() function.
Use this activity to recover all the keys from an associative array.
array_pop($arr) : This function removes an element from the end of an array.
array_push($arr, $val) : This function adds an element to the end of an array.
array_shift($arr) : This function removes an element from the beginning of an array
array_unshift($arr, $val) : This function count an element to the inauguration of an array.
each($arr) : This function is most often used to iteratively traverse an array. Each time each() is called, it returns the current key-value pair and moves the array cursor forward one element. This makes it most suitable for use in a loop.
sort($arr) : This function kind the fundamentals of an array in arise form. String values will be arranged in ascending alphabetical order.
If you want to  learn more about array and its types so please join PHP Training in Chandigarh at CBitss Technologies.



0 comments:

Post a Comment