4
: | - . |
- , .
:
int mt_rand (int $min=0, int $max);
mt_rand $min $max . , 0 $max.
:
mt_rand (1, 500); // 1 500.
:
mixed abs (mixed $number);
, int float.
:
abs(-101); // 101.
:
float round (float $number);
:
round(101.2); // 101
round(101.5); // 102
round(101.7); // 102
:
int ceil (float $number);
:
ceil(26); // 26
ceil(26.01); // 27
:
int floor (float $number);
:
floor(33.02); // 33
floor(33.97); // 33
:
string base_convert (string $number, int $from, int $to);
$number $from $to.
.
base_convert (255, 10, 16); // FF
:
mixed min (mixed $arg1, mixed $arg2 mixed $argN);
mixed max (mixed $arg1, mixed $arg2 mixed $argN);
/ , ( , ).
:
min (101, 5142.22, array(27, 150, 101), '1000'); // 27.
:
float pow (float $number, float $exp);
$number $exp.
:
pow (144, 0.5); // 12.
:
int strpos (string $where, string $what, $from=0);
$what $where , ( 0, ) false . . . $from , . strrpos , , .
:
strpos (' ...', ''); // 1
():
string trim (string $text [, string $symbols]);
, (.. ). $symbols, , $symbols.
|
|
ltrim rtrim .
:
trim (' 115 '); // '115'
:
int strlen (string $text);
. Unicode.
:
strlen(' '); // 22
:
string substr (string $text, int $from [, int $length]);
$text, $from. $length, $length. .
:
substr(' ', 10, 10); // " "
:
mixed str_replace (string $from, string $to, mixed $text);
. $text ( , ) $from $to . $text . str_ireplace , str_replace, .
:
str_ireplace('', '', ' '); // " "
string substr_replace (string $text, string $to, int $from [, int $length]);
$text $from ( $length ) $to. .
:
substr_replace('5 ', "7 ", 0, 1); // "7 "
:
string htmlspecialchars (string $string [, int $quote_style [, string $charset]]);
HTML . , , HTML , , . quote_style . , ENT_COMPAT, , . ENT_QUOTES , . ENT_NOQUOTES , .
:
- & () '&'
- " ( ) '"' when ENT_NOQUOTES is not set.
- ' ( ) ''' ENT_QUOTES.
- < ( " ") '<'
- > ( " ") '>'
:
htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
// <a href='test'>Test</a>, <a href='test'>Test</a>.
string addslashes (string $str);
. str , (\), , . ('), ("), (\) NUL ( NULL ).
|
|
:
addslashes(" ' - ?"); // \' - ?
string strtolower (string $str);
(strtoupper ).
:
strtolower('InTeRnEt'); // internet
.
PHP , , , .
:
array array_merge (array $array1, array $array2 [, array $...]);
array_merge() , . .
, , , . , , , , , .
:
$array1 = array ("color" => "red", 2, 4);
$array2 = array ("a", "b", "color" => "green", "shape" => "trapezoid", 4);
$result = array_merge ($array1, $array2);
:
array("color" => green, "0" => 2, "1" => 4, "2" => a, "3" => b, "shape" => trapezoid, "4" => 4)
:
int count (mixed $var [, int $mode]);
. mode COUNT_RECURSIVE ( 1), count() . . mode - 0.
:
$food = array('fruits' => array('orange', 'banana', 'apple'),
'veggie' => array('carrot', 'collard', 'pea'));
// count
echo count($food, COUNT_RECURSIVE); // 8
// count
echo count($food); // 2
:
array array_keys (array $input [, mixed $ search_value ])
array_keys() , $input, . array_values , , .
search_value, , . , input.
:
array_keys (array (0 => 100, "color" => "red"));
:
Array('0' => 0, '1' => color);
:
bool in_array (mixed $needle, array $haystack [, bool $strict]);
$ haystack $ needle TRUE , FALSE .
$ strict TRUE in_array() types $ needle haystack.
:
<?php
function summation ($count) {
if ($count!= 0):
return $count + summation($count-1);
endif;
}
$sum = summation(10);
print "Summation = $sum";
?>
: Summation = 55
1. ?
2. ?
3. ?
4. ?
1. . ( 5, 8, 4 ):
|
|
array (array(5,3,4,4,4), array(3,5,5,5,5,5,5,4), array(4,5,5,5));
:
$array[2][1];
2. , foreach. .
3. , : , , , .
4. 50 - 30 000 ( ). , , ( ). :
, =>, , . 50 , , . ( -), , .
, - ( ). .
( , , ). . , , ( , , ).
, , -.