Tag Archives: PHP Array

array_splice

Syntax:array array_splice ( array &$input , int $offset [, int $length = 0 [, mixed $replacement ]] ) Description:Remove a portion of the array and replace it with something else <?php $input = array(“red”, “green”, “blue”, “yellow”); array_splice($input, 2); print_r($input); echo “<br/>”; $input = array(“red”, “green”, “blue”, “yellow”); array_splice($input, 1, -1); print_r($input); ?> OUTPUT Array […]

current, next, prev, end

Syntax: mixed prev ( array &$array ) Description: Checks if a value exists in an array <?php $transport = array(‘foot’, ‘bike’, ‘car’, ‘plane’); $mode = current($transport); // $mode = ‘foot’; $mode = next($transport); // $mode = ‘bike’; $mode = next($transport); // $mode = ‘car’; $mode = prev($transport); // $mode = ‘bike’; $mode = end($transport); // […]

in_array

Syntax: bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] ) Description: Checks if a value exists in an array <?php $os = array(“Mac”, “NT”, “Irix”, “Linux”,1); if (in_array(“Irix”, $os)) { echo “Got Irix<br/>”; } if (in_array(“mac”, $os)) { echo “Got mac<br/>”; }else echo ‘false<br/>’; if (in_array(“1”, $os,false)) { echo […]

PHP Array Functions

Function Example OR Syntax array_change_key_case array_chunk array_combine array_count_values array_diff array_diff_key array_diff_assoc array_diff_uassoc array_diff_ukey array_fill array_filter array_flip array_intersect array_intersect_assoc array_intersect_key array_intersect_uassoc array_keys array_key_exists array_map array_merge array_multisort array_pop array_push array_rand array_replace array_reverse array_search array_shift array_slice array_splice array_sum array_unique array_unshift array_values current, next, prev, end end sort in_array