31. array_slice (PHP 4, PHP 5) array_slice — Extract a slice of the array Description array array_slice ( array $array, int $offset [, int $length [, bool $preserve_keys]] ) array_slice() returns the sequence of elements from the array array as specified by the offset and length parameters. If offset is non-negative, the sequence will start at that offset in the array. If offset is negative, the sequence will start that far from the end of the array. If length is given and is positive, then the sequence will have that many elements in it. If length is given and is negative then the sequence will stop that many elements from the end of the array. If it is omitted, then the sequence will have everything from offset up until the end of the array. $input = array("a", "b", "c", "d", "e"); The above example will output: |
32. array_splice (PHP 4, PHP 5) array_splice — Remove a portion of the array and replace it with something else Description array array_splice ( array &$input, int $offset [, int $length [, array $replacement]] ) array_splice() removes the elements designated by offset and length from the input array, and replaces them with the elements of the replacement array, if supplied. It returns an array containing the extracted elements. Note that numeric keys in input are not preserved. If length is omitted, removes everything from offset to the end of the array. If length is specified and is positive, then that many elements will be removed. If length is specified and is negative then the end of the removed portion will be that many elements from the end of the array. Tip: to remove everything from offset to the end of the array when replacement is also specified, use count($input) for length. If replacement array is specified, then the removed elements are replaced with elements from this array. If offset and length are such that nothing is removed, then the elements from the replacement array are inserted in the place specified by the offset. Note that keys in replacement array are not preserved. If replacement is just one element it is not necessary to put array() around it, unless the element is an array itself. Returns the array consisting of removed elements. $input = array("red", "green", "blue", "yellow"); $input = array("red", "green", "blue", "yellow"); $input = array("red", "green", "blue", "yellow"); $input = array("red", "green", "blue", "yellow");
|
33. array_sum (PHP 4 >= 4.0.4, PHP 5) array_sum — Calculate the sum of values in an array Description number array_sum ( array $array ) array_sum() returns the sum of values in an array as an integer or float. $a = array(2, 4, 6, 8); echo "sum(a) = " . array_sum($a) . "n"; $b = array("a" => 1.2, "b" => 2.3, "c" => 3.4); The above example will output: |
34. array_unshift (PHP 4, PHP 5) array_unshift — Prepend one or more elements to the beginning of an array Description int array_unshift ( array &$array, mixed $var [, mixed $…] ) array_unshift() prepends passed elements to the front of the array. Note that the list of elements is prepended as a whole, so that the prepended elements stay in the same order. All numerical array keys will be modified to start counting from zero while literal keys won’t be touched. Returns the new number of elements in the array. $queue = array("orange", "banana"); array_unshift($queue, "apple", "raspberry"); print_r($queue); The above example will output: Array([0] => apple[1] => raspberry[2] => orange[3] => banana) |
35. trim (PHP 4, PHP 5) trim — Strip whitespace (or other characters) from the beginning and end of a string Description string trim ( string $str [, string $charlist] ) This function returns a string with whitespace stripped from the beginning and end of str. Without the second parameter, trim() will strip these characters: • " " (ASCII 32 (0x20)), an ordinary space. • "t" (ASCII 9 (0x09)), a tab. • "n" (ASCII 10 (0x0A)), a new line (line feed). • "r" (ASCII 13 (0x0D)), a carriage return. • "�" (ASCII 0 (0x00)), the NUL-byte. • "x0B" (ASCII 11 (0x0B)), a vertical tab. $text = "ttThese are a few words 🙂 … "; $binary = "x09Example stringx0A"; $hello = "Hello World"; var_dump($text, $binary, $hello); print "n"; $trimmed = trim($text); var_dump($trimmed); $trimmed = trim($text, " t."); var_dump($trimmed); $trimmed = trim($hello, "Hdle"); var_dump($trimmed); // trim the ASCII control characters at the beginning and end of $binary // (from 0 to 31 inclusive) $clean = trim($binary, "x00..x1F"); var_dump($clean); The above example will output: string(32) " These are a few words 🙂 … " string(28) "These are a few words 🙂 …" |
36. ltrim (PHP 4, PHP 5) ltrim — Strip whitespace (or other characters) from the beginning of a string Description string ltrim ( string $str [, string $charlist] ) Strip whitespace (or other characters) from the beginning of a string. $text = "ttThese are a few words 🙂 … "; $binary = "x09Example stringx0A"; $hello = "Hello World"; var_dump($text, $binary, $hello); print "n"; $trimmed = ltrim($text); $trimmed = ltrim($text, " t."); $trimmed = ltrim($hello, "Hdle"); // trim the ASCII control characters at the beginning of $binary The above example will output: string(30) "These are a few words 🙂 … " |
37. rtrim (PHP 4, PHP 5) rtrim — Strip whitespace (or other characters) from the end of a string Description string rtrim ( string $str [, string $charlist] ) This function returns a string with whitespace stripped from the end of str. $text = "ttThese are a few words 🙂 … "; $binary = "x09Example stringx0A"; $hello = "Hello World"; var_dump($text, $binary, $hello); print "n"; $trimmed = rtrim($text); The above example will output: string(32) " These are a few words 🙂 … " string(30) " These are a few words 🙂 …"
|
38. chop (PHP 4, PHP 5) chop — Alias of rtrim() Description This function is an alias of: rtrim(). Notes Note: chop() is different than the Perl chop() function, which removes the last character in the string. |
39. chown (PHP 4, PHP 5) |
40. chr (PHP 4, PHP 5) chr — Return a specific character Description string chr ( int $ascii ) Returns a one-character string containing the character specified by ascii. This function complements ord(). $str = "The string ends in escape: "; $str .= chr(27); /* add an escape character at the end of $str */ /* Often this is more useful */ $str = sprintf("The string ends in escape: %c", 27); |
Leave a comment