Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
38 views10 pages

PHP Basics: Arrays, Operators, and Sessions

The document provides an overview of various PHP concepts including types of arrays, arithmetic operators, abstract classes, sticky forms, validation, and session management. It also explains the differences between static and dynamic websites, how to declare variables, and the use of functions like count(), explode(), and print_r(). Additionally, it covers form submission methods, cookies, and the $_SERVER and $_SESSION superglobal arrays.

Uploaded by

sushant.01t
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views10 pages

PHP Basics: Arrays, Operators, and Sessions

The document provides an overview of various PHP concepts including types of arrays, arithmetic operators, abstract classes, sticky forms, validation, and session management. It also explains the differences between static and dynamic websites, how to declare variables, and the use of functions like count(), explode(), and print_r(). Additionally, it covers form submission methods, cookies, and the $_SERVER and $_SESSION superglobal arrays.

Uploaded by

sushant.01t
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

a) List the types of array.

  Indexed Arrays
  Associative Arrays
  Multidimensional Arrays

b) What are different arithmatic operators in PHP?


 Addition (+)

 Subtraction (-)

 Multiplication (*)

 Division (/)

 Modulus (%)

• Exponentiation (**)
c) What is abstract class in PHP?
An abstract class in PHP is a class that cannot be instantiated on its own and
must be extended by other classes. It can contain abstract methods, which
are methods declared without a body, and the child classes must implement
these methods.

d) Define sticky form.


A sticky form is a form that retains its input values after the form is
submitted. This is useful for preserving user input in case of validation errors,
so users do not have to re-enter information.

e) What is validation?
Validation is the process of ensuring that user input meets certain criteria
before it is processed. This can include checking for required fields, data
formats, data types, and specific value ranges.

f) What is use of array-slice () in PHP?


Use of array_slice() in PHP: The array_slice() function is used to extract a
portion of an array. It takes an array, an offset (starting point), and an
optional length parameter to return a new array containing the specified
range of elements.
g) What are the databases supported by PHP?
 MySQL

 PostgreSQL

 SQLite

 Oracle

 MS SQL Server

 MariaDB

 MongoDB (with appropriate extensions)

h) what is the use of session?


Sessions in PHP are used to store user information across multiple pages.
This allows for data persistence, such as maintaining user login status,
storing shopping cart contents, and tracking user activity.

i) Which attribute is used for multiple selections in


select tag?
<select> Tag: The multiple attribute allows for multiple selections in a
<select> tag

j) What is the purpose of break statement?


The break statement is used to exit a loop or switch statement prematurely,
before it has run its natural course. This can be useful for stopping execution
when a certain condition is met.
a) Explain difference between static and dynamic
website.

Static Website Dynamic Website

Content Generation: Static Content Generation: Dynamic


websites consist of fixed content, which websites generate content on the fly,
is written in HTML, CSS, and sometimes often using server-side languages like
JavaScript. The content does not change PHP. The content can change based on
unless manually updated by the user interactions, database queries, or
developer. other dynamic data sources.
Server Interaction: When a user Server Interaction: When a user
requests a page from a static website, requests a page from a dynamic
the server simply delivers the requested website, the server processes PHP
HTML file to the user's browser. scripts, interacts with databases if
necessary, and then sends the
generated HTML to the user's browser.

b) How to declare variable in PHP?

Variables in PHP are declared using the $ sign followed by the variable
name.

For example:

php

$variableName = "value";
c) What is the use of count ( ) in PHP?

The count() function in PHP is used to count the number of elements in an


array.

For example:

$array = array(1, 2, 3, 4);


echo count($array); // Outputs: 4
d) What is a session ?
A session is a way to store information (in variables) to be used across
multiple pages. Unlike cookies, the information is not stored on the user’s
computer. Sessions are used to preserve state information on the server
across different pages, like user authentication details.

e) What is cookie?
A cookie is a small piece of data that a server sends to a user's web browser.
The browser may store it and send it back with the next request to the same
server. Cookies are used to remember information about the user, such as
login status or preferences, across different pages and visits.

f) Explain PHP explode ( ) function.

The explode() function in PHP splits a string by a specified delimiter into


an array of strings.

For example:

$string = "Hello, world!";


$array = explode(", ", $string);
// $array will be: ["Hello", "world!"]
g) How to concate two strings in PHP?
Two strings in PHP can be concatenated using the dot (.) operator.

For example:

$string1 = "Hello";
$string2 = "World";
$concatenatedString = $string1 . " " . $string2; // Outputs: "Hello
World"
h) What is PHP?
PHP (Hypertext Preprocessor) is a widely-used open source server-side
scripting language designed for web development. It can be embedded into
HTML and is especially suited for web development to produce dynamic web
pages.

i) Explain $ - SERVER
$_SERVER is a superglobal array in PHP that contains information about
headers, paths, and script locations. It is an associative array that includes
information such as:

a) $_SERVER['PHP_SELF'] - The filename of the currently executing


script.
b) $_SERVER['SERVER_NAME'] - The name of the server host.
c) $_SERVER['HTTP_USER_AGENT'] - The user agent string of the
browser

j) Describe echo statement in PHP.

The echo statement in PHP is used to output one or more strings. It is a


language construct, not a function, so parentheses are not required.

For example:

echo "Hello, world!";


.

a) What is PHP?
PHP (Hypertext Preprocessor) is a widely-used open source server-side
scripting language designed for web development. It can be embedded
into HTML and is especially suited for web development to produce
dynamic web pages.

b) What is difference between “echo” and “print”?

 echo: It is a language construct and not a function, so it can be used without parentheses.
It can take multiple parameters (although this is rarely used). It is faster than print and does
not return any value.

 print: It is also a language construct but behaves like a function in that it always returns 1.
It can only take a single parameter.

c) What is the use of isset ( ) function?


The isset() function is used to determine if a variable is set and is not NULL. It
returns true if the variable exists and has a value other than NULL, and false
otherwise.

d) Which are the methods to submit form?

Forms can be submitted using two main methods:

 GET: The form data is appended to the URL and is visible in the
address bar. It is useful for retrieving data.
 POST: The form data is included in the body of the HTTP request. It is
used for sending data to the server.

e) Explain setcookie ( ) in PHP.


The setcookie() function is used to set a cookie in the user's browser. Cookies
are used to store user-specific information between sessions. The function
must be called before any output is sent to the browser.

f) What is $-SESSION in PHP?


$_SESSION is a superglobal array used to store session variables. These
variables persist across different pages during a user's visit to a website. It
allows for data to be stored on the server rather than the client, providing a
way to keep track of user state and preferences.

g) Explain split ( ) function in PHP.


The split() function is used to split a string into an array by a regular
expression. However, this function is deprecated as of PHP 5.3.0 and
removed as of PHP 7.0.0. The recommended function to use instead is
preg_split().

h) What does PEAR stands for?


PEAR stands for PHP Extension and Application Repository. It is a
framework and repository for reusable PHP components, providing a
structured library of code and a distribution system for PHP software
packages.

i) What is the use of print_r ( )?


The print_r() function is used to print human-readable information about a
variable. It is particularly useful for displaying arrays and objects in a way
that shows their structure and contents.

j) What does the unset ( ) function mean?


The unset() function is used to destroy a given variable. It makes the variable
undefined, freeing up any memory associated with it.
a) Describe echo statement in PHP.

The echo statement in PHP is used to output one or more strings. It is a


language construct, not a function, so parentheses are not required.

For example:

echo "Hello, world!";

b) How to concate two strings in PHP?


Two strings in PHP can be concatenated using the dot (.) operator.

For example:

$string1 = "Hello";
$string2 = "World";
$concatenatedString = $string1 . " " . $string2; // Outputs:
"Hello World"
c) How to declare variable in PHP?

Variables in PHP are declared using the $ sign followed by the variable
name.

For example:

php

$variableName = "value";
d) Which are the methods to submit form?

Forms can be submitted using two main methods:

 GET: The form data is appended to the URL and is visible in the
address bar. It is useful for retrieving data.
 POST: The form data is included in the body of the HTTP request. It is
used for sending data to the server.

e) What is the purpose of break statement?


The break statement is used to exit a loop or switch statement prematurely,
before it has run its natural course. This can be useful for stopping execution
when a certain condition is met.

f) Explain $ - SERVER
$_SERVER is a superglobal array in PHP that contains information about
headers, paths, and script locations. It is an associative array that
includes information such as:

$_SERVER['PHP_SELF'] - The filename of the currently executing script.

$_SERVER['SERVER_NAME'] - The name of the server host.

$_SERVER['HTTP_USER_AGENT'] - The user agent string of the


browser

g) Explain split ( ) function in PHP.


The split() function is used to split a string into an array by a regular
expression. However, this function is deprecated as of PHP 5.3.0 and
removed as of PHP 7.0.0. The recommended function to use instead is
preg_split().
h) What is validation?
Validation is the process of ensuring that user input meets certain criteria
before it is processed. This can include checking for required fields, data
formats, data types, and specific value ranges.

i) What is the use of print_r ( )?


The print_r() function is used to print human-readable information
about a variable. It is particularly useful for displaying arrays and
objects in a way that shows their structure and contents.
j) Explain difference between static and dynamic
website.

Static Website Dynamic Website

Content Generation: Static Content Generation: Dynamic


websites consist of fixed content, which websites generate content on the fly,
is written in HTML, CSS, and sometimes often using server-side languages like
JavaScript. The content does not change PHP. The content can change based on
unless manually updated by the user interactions, database queries, or
developer. other dynamic data sources.
Server Interaction: When a user Server Interaction: When a user
requests a page from a static website, requests a page from a dynamic
the server simply delivers the requested website, the server processes PHP
HTML file to the user's browser. scripts, interacts with databases if
necessary, and then sends the
generated HTML to the user's browser.

You might also like