Monday, 22 September 2014

PHP Functions - List and Their Usage

php development
PHP comes up with a string of internal or built-in functions which are all used in certain situations to fulfill certain conditions, by simply passing certain values against them. To be frank, the scripting language comes up with nearly 3000 embedded functions. Hence, it is quite impossible to discuss all of them. The language comes up with a manual, which includes a comprehensive documentation of each of them along with example code. Besides, the manual also provides a feature containing the user comments that provide valuable tips to the users. It also comes up with discussions of some common problems that are generally faced by users and documented solutions of the same. There is also a short cut to get to the manual page quickly.

PHP editors generally have the expertise of showing the built-in functions and they use a different color so that the users know that they are built-in ones.

Let us, in this article discuss some of the most important PHP functions and their usage in a comprehensive way.

Functions that define Arbitrary number of arguments
One of the most significant features of PHP is that it provides the option of defining the functions with various optional arguments. However, there is yet another option that completely allows an arbitrary number of functional arguments.

There are a number of PHP functions that come with long as well as descriptive names. Therefore, whenever it is needed to call for a particular function, it becomes really hard to name it, unless and until the user is somewhat familiar with the term and its functionality from any other source.

Glob()
This particular function is used for searching out any pre designated file or files from the database. Technically speaking, this function returns an array or a string of filenames as well as directories by matching them in accordance to a pre medicated or specified pattern. It also returns FALSE on failure to do so.

Actually, it is a more advanced or capable edition or the scandir() that also searches files by using a definite pattern.

MIU or Memory Usage Information

memory-get-usage()
PHP comes up with a typical garbage collector along with a memory manager that is pretty complex in structure as well as functionality. Hence, the amount or extent of memory that is used in a particular script can fluctuate when the script in question is being executed. Hence, the function ‘memory-get-usage()’ can be used to collect the extent of current memory usage at any given point in time.

memory-get_usage()
This particular function is used for getting the highest memory value that is used at any point in time.

Information for CPU Usage

getrusage()
This is another function that is designed to return an associative array that contains data that is returned from a system call. All the entries associated with this function are accessible with the use of their associated documented field names.

Magic Constants
PHP also features eight ‘magic constants’ that are pretty useful, especially when it comes to fetching the current number of the line, current file path, directory path, current trait, the name of the function called, name of the class, method name and the namespace.

These are actually some predefined constants for any script that it runs. Majority of these 8 constants comes up with various extensions and cane used only when those particular extensions are available, either through the process of dynamic loading or simply because they have been assembled or compiled in the script in question. Hence, from that point of view, these constants can well be termed as functions.

Generation of unique IDs
There are instances that demand generation of a string that is absolutely unique. For this the md5() can be used, though this particular function was not developed for this reason. However, even though the strings are ideally unique, they at times come up with first few characters that are similar to other strings, mainly because these strings are all related to server time. Hence, in order to minimize the chance of duplication, a prefix can be passed or created and the second parameter can be added to increase the entropy.

serialize() and unserialize()
As and when the need of storing a complex variable in a text file or a database arises, there is no requirement of converting the objects or arrays into formatted strings. PHP comes up with a couple of extremely valuable functions – ‘serialize()’ and ‘unserialize()’ that serialize the variables or revert the serialization if and when needed.

String Compression

gzcompress() and gzuncompress()
Generally ‘zip’ option is used for file compression. However, when it comes to compressing or decompressing loose strings in PHP, the two functions - gzcompress() and gzuncompress() can be used respectively.

As mentioned at the start of this article, there are innumerable functions that PHP is equipped with. However, these are some of the most popular, useful as well as widely used functions that make the life of the developers easier.You can get in touch with a php development company in India who can help you build web apps within allocated budgets and time schedules.

We provide php application development services. If you would like to hire certified php developer for your development needs, Please contact us at Mindfire Solutions.

No comments:

Post a Comment