Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Beginner guide of PHP Functions

PHP stands for Hypertext Preprocessor. PHP (recursive abbreviation for PHP: Hypertext Preprocessor) is a broadly utilized open source universally useful scripting language that is particularly appropriate for web advancement and can be implanted into HTML. It permits web designers to make dynamic substances that associate with databases. PHP is basically used for developing web-based software applications.

What is a function?

Laravel provides us many built-in helper partner works that you can call anyplace inside your application. They make you work process advantageous for working with exhibits and articles, ways, strings, URLs and different sorts.
Arrays & Objects, Paths, Strings, URLs, Miscellaneous,

Arrays & Objects:-

Array can hold more than one variable where as an object is an independent entity which has its own arguments and methods. We usually use foreach loop to loop through them.
In laravel, data is returned in the form of model instance as object. When the query response has multiple results, then data is returned in the form of an array that contains objects.

Paths:-

Paths means group of helpers that returns absolute paths of different directories in you laravel like config, public, resource, and your base path as well.

Strings:-

Strings usually work as that Helpers in this group work with string control. You can change over strings to camel case, discover the basename of the class, run htmlspecialchars, convert content to kebab case, convert content to snake case, and perform numerous different kinds of string controls.

Basic string creation:-

Single quote, double quote, heredoc

Single quote:-

Double quote:-

Double quote strings will show a large group of got away characters , and variables in the strings will be assessed. A significant point here is that you can use curly braces to isolate the name of the variable you want evaluated.

here doc:-

Here doc for multi-line strings that require formatting and variable interpolation.

Print function:-

String functions:-

strtolower, strtoupper, strlen, strpos,
str_replace, substr, str_split

URLs:-

URLs means group of helpers with generating URLs. URLs you can generate for the controller action, named route.

Creating/Calling a function:-

PHP has a lot of built-in functions, addressing to every much every need. All the more significantly, however, it has the capacity for you to characterize and utilize your very own capacities for whatever reason. The syntax structure for making your very own capacity is

Passing/Default parameters:-

When creating functions in PHP it is possible to provide default parameters so that a parameter isn’t passed to the capacity it is as yet accessible inside the capacity with a pre-characterized esteem. These default esteems can likewise be called optional parameters since they don’t should be passed to the capacity. I have seen this kind of code being incorrectly quite often recently as of late so I figured I would go over it in a post.

Returning values:-

Values are returned by utilizing the discretionary return explanation. Any sort might be returned, including arrays and objects. This makes the capacity end its execution promptly and pass control back to the line from which it was called. See return for more data.

Variable functions:-

PHP supports the concept of variable capacities. This implies if a variable name has brackets attached to it, PHP will search for a capacity with a similar name as whatever the variable assesses to, and will endeavor to execute it. In addition to other things, this can be utilized to actualize callbacks, work tables, etc.

Variable scope:-

Variables have a limited “scope”, or “places from which they are accessible”. Because you composed $foo = ‘bar’; when some place in your application doesn’t mean you can allude to $foo from wherever else inside the application. The variable $foo includes a specific extension inside which it is legitimate and just code in the same scope has access to the variable.

Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)