1.What is PHP ?
- Server Side Scripting Language
- Client Side Scripting Language
- Pascal Programming
- Logic Programming
Ans: a
- Can we Develop Desktop applications using PHP
- Yes
- No
Ans: a
- Find the Standard Tag below
- <?php ?>
- <? ?>
- <% %>
- <script language=”PHP”> </script>
Ans: a
- Find the Scalar Data types in the below list
- Integer
- String
- Float
- Boolean
- All of the Above
Ans: e
- Check the Output for the following code ?
<?php
$x = “true”; echo $x; ?> |
- true
- 1
- boolean
Ans : a
- Output for the Following Code
<?php
$x=TRUE; $y=FALSE; $z=$y || $x; echo $z; ?> |
- TRUE
- FALSE
- 1
- Error
Ans: c
- <?php $x=” 200 ”; ?> Write the Code to convert the String Variable into Integer
Ans: $x = (int)$x;
- What is the differences between isset() and unset() functions
Ans:
isset(): using this method we can check whether the variable is set with value or not. If variable is set with value this method returns true.
unset(): using this method we can remove the value of a variable
- Output for the following code
<?php
$x = 8 – 6.4; $y = 1.6; var_dump($x == $y); ?> |
- Syntax Error
- 1
- 0
- bool(false)
- bool(true)
Ans: d
- What is an Array
_____________________________________________________
______________________________________________________
Ans: An array is a collection of values of different data types
- What is the index of the element “ d ” in the below array
$array = array(
“a”, “b”, 6 => “c”, “d”, ); |
- 4
- 0
- 7
- 5
Ans: c
- Output for the following code
<?php
echo “<pre>”;
$array = array( 1 => “a”, “1” => “b”, 1.5 => “c”, true => “d”, ); print_r($array); ?> |
A.
Array ( [1] => d [1] => b [1.5] => c [true] => d ) |
B.
Array ( [1] => d [1] => b [1.5] => c [true] => d ) |
C.
Array ( [1] => d [1] => b [1] => d ) |
D.
Array |
Ans: D
- Find the Total no.of elements in the array
<?php
$arr = array(5 => 1, 12 => 2); $arr[] = 56; $arr[“x”] = 42; unset($arr[5]); ?> |
- 4
- 3
- 0
- 2
Ans: b
- What is the difference between array_combine() and array_merge() functions
________________________________________________________________
Ans:
array_combine():
- this function creates a new array by combining the elements of exactly two arrays.
- And this function returns an array with first array values as keys and second array values as values
- Both arrays should have an equal no.of elements
array_merge():
- this function creates a new array by combining the elements of two or more arrays.
- No need to have equal no.of elements both arrays
- What is the difference between array_search() and in_array() functions
__________________________________________________________
Ans:
array_search():
- Using this method we can search for an element in an array. If element founds, this method will return the position of the element
in_array():
- Using this method we can check for an element in an array. If element founds, this methods will return true ( 1 )
- What is the method to check whether the specified key is available in an array or Not ?
- array_key()
- array_key_search()
- array_key_exists()
- array_find_key()
Ans: c
- How to Sort the below array values in descending order ?
$colors = array(‘red’, ‘blue’, ‘green’, ‘yellow’);
- sort() method
- asort() method
- arsort() method
- rsort() method
Ans: d
- What is the value of a ?
<?php
$b = 6; $a = $b++; echo $a; ?> |
- 6
- 7
Ans: 6
- What is the value of $e ?
$e = false || true
- true
- false
- none
Ans: true
- What is the value of $c ?
$a = array(“a” => “apple”, “b” => “banana”);
$b = array(“a” => “pear”, “b” => “strawberry”, “c” => “cherry”); $c = $a + $b; print_r($c); |
- Array ( [a] => apple [b] => banana [d] => pear [e] => strawberry [c] => cherry )
- Array ( [a] => apple [b] => banana [c] => cherry )
- Syntax Error
- array()
Ans: b
- What is the value of $a in the below program
$Bar = “a”;
$Foo = “Bar”; $World = “Foo”; $Hello = “World”; $a = “Hello”; $a; $$a; $$$a; $$$$a; $$$$$a; $$$$$$a; echo $a; |
- Hello
- World
- Foo
- Bar
- a
Ans: a
- Find the Magic Constants ?
- _ _LINE_ _
- _ _FILE_ _
- _ _ DIR_ _
- _ _CLASS_ _
- All of the Above
Ans: e
- What is the difference between include() and require() function
__________________________________________________
Ans:
include():
- Using this method we can include an external file into the current file.
- If the specified file is not available for inclusion it will give Warning Error
require():
- Using this method we can include an external file into the current file.
- If the specified file is not available for inclusion it will give Fatal Error
- How to get the IP address of a user in PHP
- $_SERVER[“SERVER_IP“]
- $_SERVER[“SERVER_ADDRESS”]
- $_SERVER[“IP_ADDRESS”]
- $_SERVER[“SERVER_ADDR”]
Ans: d
- What is a Query String?
___________________________________________
Ans: A Query String is a combination of key and values pairs of data, which is always appended in URL followed by ? (Question mark)
Each pair separated with & symbol
Using Query String we send some data from one location to another location
Ex: http:// example.com/test.php ? id=10&key=strore
- What is meant by persistent cookie?
__________________________________________________________
Ans: The cookies which are created expiration time are called Persistent Cookie
- Write a logic to print Prime Numbers from 1 to 20
____________________________________________________
Ans:
Answer1: <?php $count = 0; $num = 2; while ($count < 15 ) { $div_count=0; for ( $i=1; $i<=$num; $i++) { if (($num%$i)==0) { $div_count++; } } if ($div_count<3) { echo $num.” , “; $count=$count+1; } $num=$num+1; } ?> |
Answer2:
<?php $num =23; for( $j = 2; $j <= $num; $j++ ) { for( $k = 2; $k < $j; $k++ ) { if( $j % $k == 0 ) { break; } } if( $k == $j ) echo $k.”,”; } ?> |
- If i disable Cookies can we work with sessions in php?
- No
- Yes
- Yes we can work, but we will get Warning Error
Ans: a
- What is the Difference between write mode( w ) and append mode( a )
________________________________________________________
Ans:
Write Mode( W ):
- We can open a file to write the content
- For every write operation, the existing content overrides with new content
Append Mode( a ):
- We can open a file to write the content
- For every write operation, new content will appends to the existing content
- Print the below date format using Date function
Saturday, 28th March 2019
________________________________
Ans: date(“ l, dS F Y ”);
- How to find the total no.of days in current month?
- date(“ n ”);
- date(“ t ”);
- date(“ d ”);
- date(“ D ”);
Ans: b
- What is the Difference between implode() and explode() functions
_______________________________________________________
Implode():
- Using this method we can convert an array into string
explode():
- Using this method we can convert a string into array
- In File uploading, How can we move a file from temporary location permanent location
- move_file()
- move_temp_file()
- move_uploaded_file()
- is_uploaded_file()
Ans: c
- What is a Stored Procedure? Write the basic syntax to create procedure
_______________________________
Ans:
A stored procedure is a set of SQL statements.
Synatax:
create procedure <procedure-name>()
BEGIN
//Some Statements
END;
- What is the difference between primary key and candidate key?
_________________________________________________
Ans:
Primary key in MySQL is use to identify every row of a table in unique manner. For one table there is only one primary key. One of the candidate keys is the primary key and the candidate keys can be used to reference the foreign keys.
- Difference between DELETE TABLE and TRUNCATE TABLE commands in MySQL?
___________________________________________________
Ans:
Basically DELETE TABLE is logged operation and every row deleted is logged. Therefore the process is usually slow. TRUNCATE TABLE also deletes rows in a table but it will not log any of the rows deleted. The process is faster in comparison. TRUNCATE TABLE can be rolled back and is functionally similar to the DELETE statement using no WHERE clause.
- Constructor functions are called automatically at the time of Object creation
- Yes
- No
Ans: a
- How can we access a non-static member inside a function ?
- self::
- Using class name
- $this->
- static
Ans: c
- What is the use of Scope Resolution Operator (::) ?
_____________________________________
Ans: used access to static, constant, and overridden properties or methods of a class.
- Can we declare class properties using final keyword ?
- No
- Yes
Ans: a
- Write an SQL query to find second highest salary from the below emp table?
__________________________________________
Ans: SELECT MAX(salary) AS salary FROM emp WHERE salary < (SELECT MAX(salary) FROM emp);
- How can we access static members of a class ?
- By using Object
- By using Class Name
- By using $this keyword
- By Using final keyword
Ans: b
- How can we declare constants in a class ?
- define() method
- constant() method
- const keyword
- None of the Above
Ans: c
- Can we create an object for Abstract classes?
- Yes
- No
Ans: b
- What is the default uploaded filesize in php?
- 2MB
- 4MB
- 8MB
- 12MB
Ans: a
- What is function to remove HTML tags from a string?
- remove_html_tags()
- strip_tags()
- strip_html_tags()
- htmlspecialchars()
Ans: b
- What is the default storage engine in MySQL ?
- InnoDB
- MyISAM
- Memory
- CSV
Ans: a
- Can use Magic Methods in Static Context ?
- Yes
- No
Ans: b
- How can we read Form data posted by POST method in php
- $_POST
- $_GET
- $_REQUEST
- Both a and c
Ans: d
- What is the default port number of apache server?
- 90
- 8080
- 80
- 9090
Ans: c
- PHP programming was developed by
C and PERL Languages
- What are the Features of PHP ?
- PHP is Cross Platform:
It can run under any type of Operating System
Eg: Linux, Unix, Windows etc.
b.PHP is Cross Server:
It can supports different types of web servers
Eg: IIS(Internet Information Server, Tomcat, Apache etc.)
c.PHP is Cross Database:
It all types of databases . Eg: Mysql, Oracle, sql Server etc..
d.PHP is Open Source.
e.PHP supports Object Oriented Concepts.
- Faster in performance
- Within less time and less cost we can develop the applications
54. What are the PHP Coding Rules?
- In php every line should end with semi colon ( ; )
- Php file extension should be .php
- For example index.php
- All variables are declared with $ symbol
Eg: $a=10;
$v=”Hello”;
- Declaration style tags in php
Standard Tag:
<?php
echo “Hello World”;
?>
Script tag:
<script language=”PHP”>
echo “Hello”;
</script>
Note: <script> tag will never supported in latest versions of php
Short-Open Tag
<?
Echo “Hello”;
?>
Asp Tags
<%
echo “Hello”;
%>
- How can we work with asp tags and short-open tags
The php configuration settings file( php.ini ), In this file we have two configuration settings
a). asp_tags b). short_open_tag
by default these value settings are ‘off’. If we want to work with above tags we need to change the value as ‘on’.
The location of php.ini file is: C:/xampp/php/ (for XAMPP)
C:/wamp/bin/php/ ( for WAMP)
- What are the Output Statements in php ?
There are four types of output statements in php
Print :
Using this function we can print the output to the browser
On successfully written the output to browser this function returns true (true means 1)
Eg: <?php
$a=print “Hello”;//Hello
echo $a;//1
?>
Echo :
It is also used for printing the output to the browser.but it won’t return any value.
So that echo function is very fast when compared to print
eg: <?php
$a= “Hello”;
echo $a;//Hello
?>
Print_r() :
Using this function we can print the array values and object values
<?php
$ar=array(10,20,30);
Print_r($ar)//array([0]=>10[1]=>20[2]=>30)
?>
Var_dump() :
This function will print a variable with its data type
<?php
$a=10;
$b=10.5;
$c=”Welcome”;
var_dump($a);// int(10)
var_dump($b);// float(10.5)
var_dump($c);// string(7) “Welcome”
?>
57 . <?php $x=” 200 ”; ?> Write the Code to convert the String Variable into Integer
Ans: $x = (int)$x;
- How many data types are there in PHP. whar are they?
There are 3 data types:
1.Scalar types
2.Compound types
3.Special types
- What is the default port for MySQL Server?
The default port for MySQL Server is 3306.
60.What is the difference between the primary key and the candidate key?
The primary key in MySQL is used to identify every row of a table in a unique manner.
there is only one primary key per table.
The candidate keys can be used to reference the foreign keys. One of the candidate keys is the primary key.
- What are the TRIGGERS that can be used in MySQL tables?
MySQL TRIGGERS are :
BEFORE INSERT
AFTER INSERT
BEFORE UPDATE
AFTER UPDATE
BEFORE DELETE
AFTER DELETE
- What is the difference between primary key and unique key?
The primary key does not allow ‘NULL’, and duplicate values but the unique key does.
The unique key does not allow duplicate values but it allow one null value
- How can we get the version of MySQL by using Command Line?
mysql> SHOW VARIABLES LIKE “%version%”;
- What are the string types available for a column in MySQL?
Following are the string types:
SET
BLOB
ENUM
CHAR
TEXT
VARCHAR
- Write a Query to find all the indexes defined for a table?
SHOW INDEX FROM <tablename>;
- Write a query to display top 10 records in MySQL?
SELECT * FROM LIMIT 0,10;
- Write A Query To Select All Teams That Won Either 2, 4, or 6 Games?
SELECT teamname FROM teams WHERE team_won IN (2, 4, 6);