You are here: Home / Topics / Search / PHP
Showing 40 Search Results for : PHP

How to sort elements of an array in descending order in PHP?

By Vinay Kumar on 19 Nov 22 | Filed under: PHP
The below program is to sort elements of an array in descending order using PHP sort() function. The PHP echo statement is used to output the result on the screen. An array is a single variable which can store multiple values at a time.sort() function in PHPExample<!DOCTYPE html><html>&l  ......

Program to find the sum of elements in an Array in PHP

By Vinay Kumar on 19 Nov 22 | Filed under: PHP
The below program is to find the sum of elements in an array. The PHP echo statement is used to output the result on the screen. An array is a single variable which can store multiple values at a time.array_sum() function in PHP Example<!DOCTYPE html><html><body><?php    ......

How to find the product of elements in PHP array

By Vinay Kumar on 18 Nov 22 | Filed under: PHP
The below program is to find the product of elements in an array. The PHP echo statement is used to output the result on the screen. An array is a single variable which can store multiple values at a time.array_product() function in PHPExample<!DOCTYPE html><html><body><?php &nb  ......

How to convert a string into Array elements in PHP

By Deepak Sahoo on 17 Nov 22 | Filed under: PHP
The below program is to split a string as array elements based on delimiter using PHP explode() function. The PHP echo statement is used to output the result on the screen. An array is a single variable which can store multiple values at a time. The PHP explode() function is used to break a string i  ......

How to join the array elements into a String

By Deepak Sahoo on 17 Nov 22 | Filed under: PHP
The below program is to combine the array elements into a string with given delimiter using PHP join() function. The PHP echo statement is used to output the result on the screen. An array is a single variable which can store multiple values at a time. The PHP join() function is used to get a string  ......

How to merge two arrays in a new array

By Deepak Sahoo on 17 Nov 22 | Filed under: PHP
The below program is to merge two arrays into a new array using PHP array_merge() function. The PHP echo statement is used to output the result on the screen. An array is a single variable which can store multiple values at a time. The PHP array_merge() function is used to merge one or more arrays i  ......

Remove The Duplicate Values From An Array in PHP

By Deepak Sahoo on 16 Nov 22 | Filed under: PHP
The below program is to remove the duplicate values from an array using PHP array_unique() function. The PHP echo statement is used to output the result on the screen. An array is a single variable which can store multiple values at a time. The PHP array_unique() function is used to remove the dupli  ......

PHP Program for checking Palindrome number

By Vishal Gupta on 16 Nov 22 | Filed under: PHP
The below program checks for a Palindrome number using a loop. The PHP echo statement is used to output the result on the screen. A number is called as a Palindrome number if the number remains same even when its digits are reversed.Palindrome Number:abcde = edcbaExample: 24142, 1234321, etc.Example  ......

PHP Program to check Armstrong number

By Vishal Gupta on 16 Nov 22 | Filed under: PHP
The below program checks for an Armstrong number using a loop. The PHP echo statement is used to output the result on the screen. A number is called as an Armstrong number if the sum of the cubes of its digits is equal to the number itself.Armstrong Number:abc = (a*a*a) + (b*b*b) + (c*c*c)Example: 0  ......

PHP Program to print table of any number?

By Vishal Gupta on 16 Nov 22 | Filed under: PHP
The below program prints table of a number using a loop. The PHP echo statement is used to output the result on the screen.Example<!DOCTYPE html><html><body><?php    $num = 9;  for($i=1; $i<=10; $i++)   {$product = $i*$num;echo "$num * $i = $product"   ......

How to check prime number in PHP?

By Vishal Gupta on 16 Nov 22 | Filed under: PHP
The below program checks if a number is a prime or a composite number. The PHP echo statement is used to output the result on the screen.Example<!DOCTYPE html><html><body><?php$num = 13;  $count=0;  for ( $i=1; $i<=$num; $i++)  {  if (($num%$i)==0)  {  ......

PHP Program To Print Sum Of Digits

By Vishal Gupta on 16 Nov 22 | Filed under: PHP
The below program gives the sum of two variables x and y. The PHP echo statement is used to output the text and sum value to the screen. In a similar way, codes can be written to get a sum of multiple variables in PHP.Example<!DOCTYPE html>
<html>
<body>
 
<?php
$txt1   ......

PHP Program for finding the frequency of numbers in given array

By Shyam Dubey on 15 Nov 22 | Filed under: PHP
This program is useful for finding how many times any number is placed in any array. Suppose we have an array with elements as follows: $a = array (54,85,92,54,16,92,48);Output will be: 54 occurs 2 times 85 occurs 1 times 92 occurs 2 times 16 occurs 1 times 48 occurs 1   ......

PHP Program to Separate Zeros from the given Array elements

By Shyam Dubey on 15 Nov 22 | Filed under: PHP
Hello guys, this program is used to find all the zeros in any given array and shift those zeros in the last for example. Given array: 1 8 5 0 4 0 5 1 0 0 4 Output: 1 8 5 4 5 1 4 0 0 0 0Program:://To separate zeros from the given array elements<html>     <head>&nb  ......

How to convert decimal numbers to binary in PHP

By Shyam Dubey on 15 Nov 22 | Filed under: PHP
This program is written is PHP and HTML to show how to convert decimal number to binary number. Note- there is a inbuilt function in PHP which is used for converting decimal numbers to binary. decbin() function is used for this purpose. Program::// To convert Decimal number into Binary num  ......

Rules for naming variable in PHP

By Pritvik on 31 Oct 22 | Filed under: PHP
A variable starts with the $ sign, followed by the name of the variableA variable name must start with a letter or the underscore characterA variable name cannot start with a numberA variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )Variable names are case-sen

Explain NULL in PHP

By Pritvik on 31 Oct 22 | Filed under: PHP
In PHP, the special data type NULL is used to indicate the presence of solely the NULL value. It cannot have any other value assigned to it.PHP allows for the declaration of NULL in one of two ways, as illustrated below:$var = NULL:Or$var = null;In PHP, the two aforementioned syntaxes function corre

What definition does PHP give to constants?

By Pritvik on 31 Oct 22 | Filed under: PHP
Utilizing PHP's define() function makes defining constants simple. The values of the constants can be simply defined and obtained using this function.Constants cannot be modified after definition, as the name implies. It is not necessary for them to begin with the standard $ sign as is done in PHP s

What kinds of constants are predefined in PHP?

By Pritvik on 31 Oct 22 | Filed under: PHP
The following are some of the most popular constants in PHP:_METHOD_: Displays the class nameCLASS_: Provides the class name.FUNCTION_: Indicates the function name.LINE_: Indicates the working line number.FILE_: Displays the file name and its path.

Types of variable in PHP

By Pritvik on 31 Oct 22 | Filed under: PHP
The following list of PHP's eight main data types:A named, sorted collection of data is called an array.A logical value is a boolean (True or False)Double: Numbers with floating points, like 5.1525Whole numbers without a floating point represent integers.An object is a class instance that includes d  ......

What does PEAR in PHP stand for?

By Pritvik on 31 Oct 22 | Filed under: PHP
PHP Extension and Application Repository is referred to as PEAR. All of the reusable PHP components are housed in one of the frameworks and acting repositories. It not only contains some of the PHP libraries but also gives you a straightforward interface to set up packages automatically.Learn PHP MC

What is the primary use of PHP?

By Pritvik on 31 Oct 22 | Filed under: PHP
There are many applications for PHP for developers. The following are some of the most popular ideas that PHP provides:It is really simple to grant a website's necessary content-restricted access using PHP.Users can access certain cookies and set them in accordance with their needs.It is simple to d  ......

Explain rand() function in PHP

By Pritvik on 31 Oct 22 | Filed under: PHP
Hello guys, I am Pritvik Sharma. In this post, I am going to tell you what rand() function does in case of PHP. rand() function is inbuilt function in PHP which is used to generate a random integer. If you write rand() without its minimum and maximum value it will generate a random number from   ......

How to Check Website Availability with PHP

By Team MCQ Buddy on 30 Oct 22 | Filed under: PHP
Hello programmers, In this post, we are going to see how we can check website is active or not. We will make it possible with PHP and Curl. The following PHP script helps you to check if your website is online and available. If you want to check the status of your website, make a cURL request t  ......

How to Generate Random String in PHP

By Team MCQ Buddy on 30 Oct 22 | Filed under: PHP
In this tutorial, we are going to see how to generate a random string in PHP. We can achieve that by storing all possible letters in a string and then generate a random index from 0 to the length of the string -1. As shown in the following code.Generate random string in php<?php 

function getR  ......

Program for Factorial in PHP with PHP "for loop"

By Team MCQ Buddy on 30 Oct 22 | Filed under: PHP
In this post, we are going to see how to write a PHP function to calculate the factorial of a given number in PHP using for loop. The factorial of a number is the product of all integers between 1 and itself.Code<?php
  function fact($n){ 
    $f = 1; 
    for ($i = 1;  ......

How to check if a URL is valid in PHP

By Team MCQ Buddy on 30 Oct 22 | Filed under: PHP
In this tutorial, we are going to see how to check if a URL is valid in PHP. When a URL is submitted, it is very important to check if this URL is valid or not before performing any action. Here we are going to see how to check if a URL is valid in PHP using filter_var() function with FILTER_VALIDAT  ......

Difference between include () and require() function

By Sikhar Chaudhary on 09 Oct 22 | Filed under: PHP
include() functionThis function is used to copy all the contents of a file called within the function, text wise into a file from which it is called.When the file is included cannot be found, it will only produce a warning (E_WARNING) and the script will continue the execution.require() function:The  ......

For each loop in PHP

By Sikhar Chaudhary on 09 Oct 22 | Filed under: PHP
The foreach statement is a looping construct that is used in PHP to iterate and loop through the array data type.The working of foreach is simple, with every single pass of the value, elements get assigned a value, and pointers are incremented. This process is repeatedly done until the end of the ar  ......

Does JavaScript interact with PHP?

By Deepak Sahoo on 08 Oct 22 | Filed under: PHP
JavaScript is a client-side programming language, whereas PHP is a server-side scripting language. PHP has the ability to generate JavaScript variables, and this can be executed easily in the browser. Thereby making it possible to pass variables to PHP using a simple URL.

What are traits in PHP?

By Deepak Sahoo on 08 Oct 22 | Filed under: PHP
Traits are a mechanism that lets you create reusable code in PHP and similar languages where multiple inheritances are not supported. It’s not possible to instantiate it on its own.A trait is intended to reduce the limitations of single inheritance by enabling a developer to reuse sets of methods 

Types of errors in PHP

By Deepak Sahoo on 08 Oct 22 | Filed under: PHP
The 3 main types of errors in PHP are:Notices: Notices are non-critical errors that can occur during the execution of the script. These are not visible to users. Example: Accessing an undefined variable.Warnings: These are more critical than notices. Warnings don’t interrupt the script execution.   ......

What is Parser in PHP?

By Deepak Sahoo on 08 Oct 22 | Filed under: PHP
A PHP parser is software that converts source code into the code that computer can understand. This means whatever set of instructions we give in the form of PHP code is converted into a machine-readable format by the parser.You can parse PHP code with PHP using the token_get_all() function.

PHP and HTML interact

By Deepak Sahoo on 08 Oct 22 | Filed under: PHP
PHP scripts have the ability to generate HTML, and it is possible to pass information from HTML to PHP.PHP is a server-side language whereas HTML is a client-side language. So PHP executes on the server-side and gets its results as strings, objects, arrays, and then we use them to display its values

Disadvantages of PHP Language

By Deepak Sahoo on 08 Oct 22 | Filed under: PHP
The cons of PHP are:PHP is not suitable for giant content-based web applications.Since it is open-source, it is not secure. Because ASCII text files are easily available.Change or modification in the core behavior of online applications is not allowed by PHP.If we use more features of the PHP framew  ......

Rules for naming a PHP variable

By Shivam on 08 Oct 22 | Filed under: PHP
The following two rules are needed to be followed while naming a PHP variable:A variable must start with a dollar symbol, followed by the variable name. For example: $price=100; where price is a variable name.Variable names must begin with a letter or underscore.A variable name can consist of letter  ......

What are the different types of variables present in PHP?

By Shivam on 08 Oct 22 | Filed under: PHP
There are 8 primary data types in PHP which are used to construct the variables. They are:Integers: Integers are whole numbers without a floating-point. Ex: 1253.Doubles: Doubles are floating-point numbers. Ex: 7.876Booleans: It represents two logical states- true or false.NULL: NULL is a special ty  ......

Is PHP a case-sensitive language?

By Shivam on 08 Oct 22 | Filed under: PHP
PHP can be considered as a partial case-sensitive language. The variable names are completely case-sensitive but function names are not. Also, user-defined functions are not case-sensitive but the rest of the language is case-sensitive.For example, user-defined functions in PHP can be defined in low

What is a session in PHP?

By Shivam on 08 Oct 22 | Filed under: PHP
A session in PHP is a way to store information to be used across multiple pages of an entire website. The information is not stored on the user’s computer, unlike cookies. In a temporary directory on the server, a file will be created by the session where registered session variables and their val  ......