Monthly Archive: March 2014

Mar 27

useful function in php

Sort This function use for sort an array. Element will arrange lowest to highest. Syntax bool Sort($array, sortingtype or flag) Sortingtype : Optional, specify how the compare element value 1. SORT_REGULAR : Default. Compare items normally. 2. SORT_NUMERIC : Compare items numerically 3. SORT_STRING : Compare items as strings 4. SORT_STRING : Compare items as strings 5. SORT_LOCALE_STRING : Compare items …

Continue reading »

Mar 21

Array Shift and Unshift

Array_Shift : Shift an element off the beginning of array. Syntax : array_shift ( $arrval ) array_shift() shifts the first value of the array off and returns it. Return the shift value or null if array is empty. Example: $arrval = array(“test”, “test1”, “test2”, “test3”); $shiftval = array_shift($arrval); print_r($arrval); Output: array( [0] => test1 [1] => test2 [2] …

Continue reading »

Mar 21

Array Push and Pop

Array_Push : Push one or more elements onto the end of array Syntax: array_push ( $array ,  $value1 [, $value2, $value3,… ] ) array_push() treats array as a stack, and pushes the passed variables onto the end of array. Simple example: $arr[]=$val; In Above Example return the new number of element in array. Example: $arrval=array(“test”,”test1″); array_push($arrval,”test3″,”test4″); print_r($arrval); Output Array ( [0] => test [1] => test1 …

Continue reading »

Mar 21

Array Search

array_search : Searches the array for a given value and returns the corresponding key if successful. Systax: array_search ( $value ,  $array [, bool $strict = false ] ) Strict : if strict set to true then array_search() function search for identical element. Means it check type of value in the array and object must be same. Example $array = array(0 => ‘blue’, 1 => ‘red’, 2 => ‘green’, 3 => ‘red’); $key = array_search(‘green’, $array); echo $key; Output : 2 …

Continue reading »

Older posts «