Built-in Functions

Rashmi Mishra
0

 Built-in Functions

Built-in Functions are predefined functions that come with the PHP language, offering a wide range of functionalities to developers. These functions are part of the PHP core, and you can use them directly without needing to define them. Here are some examples of commonly used built-in functions in PHP: 1.strlen(): Returns the length of a string. Example: $string = "Hello, World!"; $length = strlen($string); echo $length;

Output: 13

2. count(): Returns the number of elements in an array or the number of properties in an object. $numbers = [1, 2, 3, 4, 5]; $count = count($numbers); echo $count;

Output: 5

3.implode(): Joins array elements with a string. $fruits = ["apple", "banana", "orange"]; $result = implode(", ", $fruits); echo $result;

Output: apple, banana, orange

4. array_push(): Pushes one or more elements onto the end of an array. $stack = [1, 2, 3]; array_push($stack, 4, 5); print_r($stack);

Output: Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 )

5. file_get_contents(): Reads the entire content of a file into a string. $fileContent = file_get_contents("example.txt"); echo $fileContent;

6. date(): Formats a local time/date. $currentDate = date("Y-m-d H:i:s"); echo $currentDate;

7. substr(): Returns a part of a string. $text = "Hello, World!"; $substring = substr($text, 0, 5); echo $substring;

Output: Hello



Post a Comment

0Comments

Post a Comment (0)