Found 1060 Articles for PHP

Convert object to an array in PHP.

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

9K+ 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

723 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

896 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

529 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

Concatenation of two strings in PHP

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

3K+ Views

PHP offers different kinds of operators having distinctive functionalities. Operators enable us to perform arithmetic activities, string concatenation, compare values and to perform boolean operations, more...In this article, we will learn string operators given by PHP. Let's first learn the types of string operators in php. There are two string operators provided by PHP.  1.Concatenation Operator ("."):      This operator combines two string values and returns it as a new string. 2.Concatenating Assignment operator (".="):      This operation attaches the argument on the right side to the argument on the left side. Let's demonstrate the utility of the above operators by following examples.Example:Output ... Read More

Comparison of dates in PHP

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

7K+ Views

Matching two dates in PHP is quite smooth when both the dates are in a similar format but php failed to analyze when the two dates are in an unrelated format. In this article, we will discuss different cases of date comparison in PHP. We will figure out how to utilize DateTime class, strtotime() in comparing dates.Case 1:we can analyze the dates by simple comparison operator if the given dates are in a similar format.Output:2019-03-26 is latest than 2018-11-24Explanation:Here we have declared two dates $date1 and $date2 in the same format. So we have used a comparison operator(>) to compare ... Read More

Is PHP deg2rad() equal to MySQL radians()?

George John
Updated on 30-Jul-2019 22:30:25

112 Views

Yes, both of these methods convert a degree value to radian. Let us create a table to understand MySQL radians. The query to create a table is as followsmysql> create table RadiansDemo    - > (    - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    - > Value int    - > ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into RadiansDemo(Value) values(0); Query OK, 1 row affected (0.14 sec) mysql> insert into RadiansDemo(Value) values(45); Query OK, 1 row affected (0.17 sec) mysql> insert into ... Read More

Extracting only date from datetime field in MySQL and assigning it to PHP variable?

Samual Sam
Updated on 30-Jul-2019 22:30:25

716 Views

You need to use DateTime class if you want to extract the only date from datetime field. The syntax is as follows −DateTime::createFromFormat("Y-m-d H:i:s",yourDateTimeValue)->format("yourFormatSpecifier");Now you can implement the above syntax in your PHP code to extract the only date from datetime field. The PHP code is as follows −$MySQLDataBaseDateTime = "2018-02-13 13:10:15"; echo DateTime::createFromFormat("Y-m-d H:i:s",$MySQLDataBaseDateTime)->format("d/m/Y");Here is the screenshot of the PHP code −Output13/02/2018

How to add auto-increment to column in MySQL database using PhpMyAdmin?

karthikeya Boyini
Updated on 26-Jun-2020 10:21:02

10K+ Views

You can add auto_increment to a column in MySQL database with the help of ALTER command.The syntax is as follows −ALTER TABLE yourTableName MODIFY yourColumnName INT NOT NULL AUTO_INCREMENT;To open PhpMyAdmin on localhost, you need to type the following on localhost and press enter −localhost/phpmyadminThe screenshot is as follows −Above, we already have a table “AutoIncrementDemo”. In that, we have a column “UserId” set as Primary key. Let’s say we need to add auto_increment to the same column.For auto_increment, check the A.I as shown above. The same is marked below as well −After that press the Save button.Let us also ... Read More

How can I get enum possible values in a MySQL database using PHP?

Samual Sam
Updated on 26-Jun-2020 09:59:16

2K+ Views

You can get the enum possible values in a MySQL database with the help of INFORMATION_SCHEMA.COLUMNS table. The syntax is as follows −SELECT    COLUMN_TYPE AS anyAliasName FROM    INFORMATION_SCHEMA.COLUMNS WHERE    TABLE_SCHEMA = ‘yourDatabaseName’ AND TABLE_NAME = 'yourTableName' AND COLUMN_NAME = 'yourEnumColumnName';To understand the above syntax, let us create a table with an ENUM data type. The query to create a table is as follows −mysql> create table EnumDemo -> ( -> Id int, -> Color ENUM('RED', 'GREEN', 'BLUE', 'BLACK', 'ORANGE') -> ); Query OK, 0 rows affected (0.66 sec)Here the table ‘EnumDemo’ is present in the ‘sample’ database. ... Read More

Advertisements