php

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Variables in php?

In PHP, a variable starts with the $ sign, followed by the name of the variable: Note: When you assign a text value to a variable, put quotes around the value. Think of variables as containers for storing data.

PHP case sensitive?

In PHP, all keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are NOT case-sensitive. however variables are case-sensitive.

PHP The static Keyword

Normally, when a function is completed/executed, all of its variables are deleted. However, sometimes we want a local variable NOT to be deleted. We need it for a further job. To do this, use the static keyword when you first declare the variable:

what are the output variables?

The PHP echo statement is often used to output data to the screen.

Replace Text Within a String

The PHP str_replace() function replaces some characters with some other characters in a string. <?php echo str_replace("world", "Dolly", "Hello world!"); // outputs Hello Dolly! ?>

Count The Number of Words in a String

The PHP str_word_count() function counts the number of words in a string: <?php echo str_word_count("Hello world!"); // outputs 2 ?>

PHP string functions Get The Length of a String

The PHP strlen() function returns the length of a string. <?php echo strlen("Hello world!"); // outputs 12 ?>

Search For a Specific Text Within a String

The PHP strpos() function searches for a specific text within a string. If a match is found, the function returns the character position of the first match. If no match is found, it will return FALSE. <?php echo strpos("Hello world!", "world"); // outputs 6 ?>

Reverse a String

The PHP strrev() function reverses a string: <?php echo strrev("Hello world!"); // outputs !dlrow olleH ?>

PHP the global keyword?

The global keyword is used to access a global variable from within a function.

PHP variables scope?

The scope of a variable is the part of the script where the variable can be referenced/used. PHP has three different variable scopes: local global static You can have local variables with the same name in different functions, because local variables are only recognized by the function in which they are declared.

PHP resource

The special resource type is not an actual data type. It is the storing of a reference to functions and resources external to PHP.

PHP array

array stores multiple values in one single variable <?php $cars = array("Volvo","BMW","Toyota"); var_dump($cars); ?> $cars is an array.

creating a constant

define(name, value, case-insensitive) name: Specifies the name of the constant value: Specifies the value of the constant case-insensitive: Specifies whether the constant name should be case-insensitive. Default is false case sensitive. <?php // case-insensitive constant name define("GREETING", "Welcome to W3Schools.com!", true); echo greeting; ?> constants are global. <?php define("GREETING", "Welcome to W3Schools.com!"); function myTest() { echo GREETING; } myTest(); ?>

ways to get output from php?

echo and print

Php string

string is a sequence of characters. <?php $x = "Hello world!"; $y = 'Hello world!';

PHP boolean.

two possible status: true or false. $x = true; $y = false;

PHP data types

variables can store different data types. and different data types use different types. String Integer Float (floating point numbers - also called double) Boolean Array Object NULL Resource

how does php script start and end?

<?php and end with ?>

what is a comment? how to comment in php?

A comment in PHP code is a line that is not read/executed as part of the program. Its only purpose is to be read by someone who is looking at the code. // This is a single-line comment # This is also a single-line comment /* This is a multiple-lines comment block that spans over multiple lines */

Php integer

An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647. Rules for integers: An integer must have at least one digit An integer must not have a decimal point An integer can be either positive or negative Integers can be specified in three formats: decimal (10-based), hexadecimal (16-based - prefixed with 0x) or octal (8-based - prefixed with 0) var_dump() function returns the data type and value: <?php $x = 5985; var_dump($x); ?> output int(5985)

PHP object

An object is a data type which stores data and information on how to process that data. First we must declare a class of object. For this, we use the class keyword. A class is a structure that can contain properties and methods:

conditional statements

Conditional statements are used to perform different actions based on different conditions.

conditional statements

Conditional statements are used to perform different actions based on different conditions. if statement - executes some code if one condition is true if...else statement - executes some code if a condition is true and another code if that condition is false if...elseif....else statement - executes different codes for more than two conditions switch statement - selects one of many blocks of code to be executed

Constants

Constants are like variables except that once they are defined they cannot be changed or undefined. A constant is an identifier (name) for a simple value. The value cannot be changed during the script. A valid constant name starts with a letter or underscore (no $ sign before the constant name). Note: Unlike variables, constants are automatically global across the entire script.

PHP null value

Null is a special data type which can have only one value: NULL. A variable of data type NULL is a variable that has no value assigned to it. Tip: If a variable is created without a value, it is automatically assigned a value of NULL. Variables can also be emptied by setting the value to NULL:

Operators

Operators are used to perform operations on variables and values. Arithmetic operators Assignment operators Comparison operators Increment/Decrement operators Logical operators String operators Array operators

Global variable?

PHP also stores all global variables in an array called $GLOBALS[index]. The index holds the name of the variable. This array is also accessible from within functions and can be used to update global variables directly. <?php $x = 5; $y = 10; function myTest() { $GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y']; } myTest(); echo $y; // outputs 15 ?>

what can php do?

PHP can generate dynamic page content PHP can create, open, read, write, delete, and close files on the server PHP can collect form data PHP can send and receive cookies PHP can add, delete, modify data in your database PHP can be used to control user-access PHP can encrypt data

What is php

PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.

PHP full form?

PHP: Hypertext Preprocessor"

PHP Float

Php float is decimal number and exponential form. <?php $x = 10.365; var_dump($x); ?> output 10.365

what are rules for php variables?

Rules for PHP variables: A variable starts with the $ sign, followed by the name of the variable A variable name must start with a letter or the underscore character A variable name cannot start with a number A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) Variable names are case-sensitive ($age and $AGE are two different variables)


संबंधित स्टडी सेट्स

Final Chapter 13, Chapter 11, Chapter 13: Groups & Teams, Chapter 13 Admin Mgmt, Chapter 12, CHAPTER 12: 3370 MGT EXAM 3

View Set

RN Maternal Newborn Online Practice 2019 B with NGN

View Set

Chapter 8: Weathering, Soil, and Mass Movement

View Set

Chapter 31: The Child with Musculoskeletal or Articular Dysfunction

View Set

French Revolution Causes Quizlet

View Set

Unit 10 - Musculoskeletal + Derm

View Set