Backend Development 7 min read

Common PHP Functions for Arrays, Strings, Dates, Files, and Directories

This article provides a concise reference of frequently used PHP functions for handling arrays, strings, dates and times, databases, files, and directories, highlighting each function’s purpose, typical parameters, and return values to aid developers in efficient backend programming.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Common PHP Functions for Arrays, Strings, Dates, Files, and Directories

1. Common PHP Array Functions

(1) array() – create an array.

(2) in_array() – check if a value exists in an array.

(3) count() – return the number of elements in an array.

(4) array_merge() – merge multiple arrays into one.

(5) array_diff() – compute the difference between arrays.

(6) array_intersect() – get the intersection of arrays.

(7) array_keys() – retrieve all keys from an array.

(8) array_values() – retrieve all values from an array.

(9) array_unique() – remove duplicate values.

(10) array_push() – push one or more elements onto the end of an array.

(11) array_pop() – pop and return the last element of an array.

(12) array_walk() – apply a user‑defined callback to each element.

2. Common PHP String Functions

(1) trim() – strip whitespace (or other characters) from the beginning and end of a string.

(2) strlen() – get the length of a string.

(3) mb_strlen() – get the length of a multibyte string with a specified encoding.

(4) substr() – return a portion of a string.

(5) str_replace() – replace occurrences of a substring.

(6) str_repeat() – repeat a string a given number of times.

(7) is_string() – check whether a variable is a string.

(8) str_shuffle() – randomly shuffle characters in a string.

(9) sprintf() – return a formatted string.

(10) strstr() – find the first occurrence of a substring.

(11) addslashes() – escape characters with backslashes.

3. Common PHP Date/Time Functions

(1) date() – format a local date/time.

(2) getdate() – retrieve date/time information as an array.

(3) date_default_timezone_set() – set the default timezone.

(4) date_default_timezone_get() – get the default timezone.

(5) mktime() – get a Unix timestamp for a specific date.

(6) strtotime() – parse an English textual datetime description into a Unix timestamp.

(7) strftime() – format a local date/time according to locale settings.

4. Common PHP File Functions

(1) fopen() – open a file.

(2) fgets() – read a line from a file (note: file_get_contents() also reads files).

(3) fwrite() – write data to a file (note: file_put_contents() can also write files).

(4) fclose() – close an open file handle.

(5) rename() – move or rename a file.

(6) copy() – copy a file.

(7) vim or touch – create a new file.

(8) unlink() – delete a file.

(9) fileatime() – get the last access time of a file.

(10) filemtime() – get the last modification time of a file.

(11) filesize() – get the size of a file.

(12) filetype() – get the type of a file.

(13) stat() – retrieve detailed file status information.

(14) is_dir() – determine if a path is a directory.

5. Common PHP Directory Functions

(1) opendir() – open a directory.

(2) readdir() – read an entry from an open directory.

(3) rmdir() – remove a directory.

(4) closedir() – close a directory handle.

(5) mkdir() – create a new directory.

(6) dirname() – return the directory portion of a path.

(7) getcwd() – get the current working directory.

(8) scandir() – list files and directories inside a specified path.

BackendDateTimefunctionsarraysstringsfile handling
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.