Found 1046 Articles for PHP

What is "namespace" keyword in PHP?

Alok Prasad
Updated on 31-Dec-2019 08:53:49

334 Views

In this article, we are going to learn about namespace in PHP. In PHP when we are creating large applications or when integrating third-party applications/library then there may be chances of collision between class names, function names. So to avoid these problems PHP "Namespaces" provide a way in which to group related classes, interfaces, functions and constants.Let's see the syntax of declaring namespace below.SyntaxIn the PHP world, namespaces are intended to take care of two issues that creators of libraries and applications experience when making re-usable code components, Those are:1.Name impact between code you create, and internal PHP classes/functions/constants or ... Read More

How to display two decimals in MySQL/PHP?

Arjun Thakur
Updated on 31-Dec-2019 08:52:20

275 Views

To display two decimals, use number_format(). Let us first write the PHP code for the same. We have first declared two variables are initialized −$number1=10.3423; $number2=10;Now, display the two decimals using the number_format() function −$result1=number_format ($number1, 2); $result2=number_format ($number2, 2);ExampleFollowing is the example −OutputFollowing is the snapshot of PHP code −10.34 10.00

What is method overloading in PHP?

Alok Prasad
Updated on 31-Dec-2019 08:29:38

9K+ Views

Method Overloading is a concept of Object Oriented Programming which helps in building the composite application in an easy way. Function overloading or method overloading is a feature that permits making creating several methods with a similar name that works differently from one another in the type of the input parameters it accepts as arguments.The above concept is fine for other programming languages and it is called static polymorphic i.e method overloading.ExampleLet's understand through an example.Output:ErrorExplanation:This will generate an error since php will say you have declared this method twice.But Other programming languages says , doTask($var1) and doTask($var1, $var2) are ... Read More

Explain include(),require(),include_once() and require_once() functions in PHP.

Alok Prasad
Updated on 30-Jul-2019 22:30:26

3K+ Views

In this article, we will learn about useful and important functions in PHP for file inclusion. All these functions require, require_once, include and include_once are utilized to include the files in the php page but there is a slight distinction among them in terms of functionality.Let's discuss these functions below with their functionality.include() :This function is used to include a file in a PHP page. If include() function is not able to find a specified file on location at that time it will throw a warning message however, it will not stop script execution.require():This function is utilized to add a ... Read More

Explain difference between Abstraction and Encapsulation in PHP.

Alok Prasad
Updated on 31-Dec-2019 08:20:07

1K+ Views

PHP5 added the object-oriented programming approach with the previous version, which is used for making code reusable in real time php application.Some of the concepts of object-oriented models are: class, object, encapsulation, polymorphism, abstract and final classes, and methods, interfaces and inheritance, etc...Here we discuss the basic differences between abstraction and encapsulation.Encapsulation:Encapsulation is an approach that joins data members(variables) and implementation details into a single unit called the class that implies class is formed with variables and methods present inside it.Encapsulation is a protection mechanism for data members present inside the class i.e data members are not accessible by end ... Read More

Explain final class and final method in PHP.

Alok Prasad
Updated on 30-Jul-2019 22:30:26

1K+ Views

The final keyword is introduced by PHP5 related to the object-oriented programming concept.But before we move on to the final, we need to ensure that we have a good understanding of the inheritance concept. In inheritance, we can inherit a class from another class. Also, we can override a function in an inherited class, to replace the behavior originally provided. In some cases, we might need to keep a class from being inherited from or we may need to prevent a function to be overridden. This can be achieved with the final, by prefixing the class and function with the ... Read More

Convert object to an array in PHP.

Alok Prasad
Updated on 30-Jul-2019 22:30:26

8K+ Views

In a PHP application, we are working with data in various formats such as string, array, objects or more...In a real-time application, we may need to read a php object result in the form of an associative array to get the desired output.So we will discuss here how to transform a php object to an associative array in PHP.Let's explain what is an object and associative array in PHP? An object is an instance of a class meaning that from one class you can create many objects. It is simply a specimen of a class and has memory allocated. While ... Read More

Explain STATIC AND INSTANCE method in PHP.

Alok Prasad
Updated on 31-Dec-2019 08:18:24

564 Views

In PHP, instance methods are the preferable practice over static methods. In any case, it isn't to say that static methods are not helpful, they have a distinct and unique purpose. Here we discuss a comparison between static and instance methods in PHP.Here Note that instance method is always connected to the object of the class while on the other hand static methods always connected with the class.First talk about static method. The static method in PHP is the same as other Object Oriented Programming Languages. Important cases for using the static method in PHP.The static method required to be ... Read More

Comparison of floating point values in PHP.

Alok Prasad
Updated on 31-Dec-2019 08:15:59

647 Views

In PHP, testing floating point values for equality is problematic, because PHP is failing when checking if one floating point number is equal to another. Despite the fact floating point numbers seems to have the same value do not need to actually be identical. So in this article will demonstrate the problem we are facing in comparison of Floating-Point Numbers and different procedures to avoid this problem.ExampleLet's test this with a simple example:output:a and b are not same.Explanation:In this code, the else condition is executed instead of the if condition, even though $a and $b are the same. It is ... Read More

Comparison between "&&" and "AND" operator in PHP.

Alok Prasad
Updated on 31-Dec-2019 09:28:32

379 Views

PHP offers incredible operators to perform operations such as arithmetic, assignment, comparison and many more ...In this article, more importance will be laid on logical operators "&&" and "AND" and will study how they can be utilized based on their precedence. Logical operators "&&" and "AND" produce true-or-false as results, and therefore these are also known as Boolean operators. Before diving into deep let's learn what is "AND" operator? "AND" operator returns true if and only if both the conditions are true. Let's take an example to demonstrate "AND" operator.ExampleOutput:TrueExplanation:Since variable $val1 = 20 and $val2 = 50, the condition $val1 ... Read More

Advertisements