PHP Output Questions
- Find Error/Output in follwing code:
- In Class A
- In Class B
- No Output
- Fatal Error
<?php
class A {
function __construct() {
echo "In Class A";
}
}
class B extends A {
function __construct() {
echo "In Class B";
}
}
class C extends B {
}
$obj = new C();
?>
Added By : Arpit
- Find Error/Output in follwing code:
- Right
- No output
- Undefined property
- None of the above
<?php
class MyClass
{
const CONST_VAR = 'Right';
function showConstant() {
echo $this->CONST_VAR;
}
}
$class = new MyClass();
$class->showConstant();
?>
Added By : Anjana
- Find Error/Output in follwing code:
- sumit
- @gmail.com
- gmail.com
- sumit@
<?php
$email = 'sumit@gmail.com';
$user = strstr($email, '@', true);
echo $user;
?>
Answer :
A
Explanation:
strstr() returns part of a given string from the first occurrence of a search string to the end of the string.
stristr() is idential to strstr() except that it is case insensitive.
if pass "true" in third parameter in strstr(string, search_string, true). it returns part of given string before the first occurrence of a search string.
Added By : Sumit
- Find Error/Output in follwing code:
- Integer Integer
- Integer Not Integer
- Not Integer Integer
- Not Integer Not Integer
<?php
$val1 = 42;
if(is_numeric($val1)) {
echo "Integer";
} else {
echo "Not Integer";
}
$val2 = '42';
if(is_numeric($val2)) {
echo "Integer";
} else {
echo "Not Integer";
}
?>
Answer :
A
Explanation:
is_numeric() - Finds whether a variable is a number or a numeric string
Added By : Rohit
- Find Error/Output in follwing code:
- Not Integer Integer
- Integer Not Integer
- Integer Integer
- Not Integer Not Integer
<?php
$val1 = 42;
if(ctype_digit($val1)) {
echo "Integer";
} else {
echo "Not Integer";
}
$val2 = '42';
if(ctype_digit($val2)) {
echo "Integer";
} else {
echo "Not Integer";
}
?>
Answer :
A
Explanation:
ctype_digit - Checks if all of the characters in the provided string, text, are numerical.
$val1 = 42. ASCII 42 is the * character and * is not a numeric. function return false.
Added By : Rohit
- Find Error/Output in follwing code:
- The string does not consist of all letters.
- The string consists of all letters.
- Fatal Error
- Syntax Error
<?php
$strings = 'test test';
if (ctype_alpha($strings)) {
echo "The string consists of all letters.";
} else {
echo "The string does not consist of all letters.";
}
?>
Answer :
A
Explanation:
ctype_alpha() returns TRUE if every character in text is a letter[A-Za-z] do not include space, FALSE otherwise.
Added By : Rohit
Also Exercise
Post Your Question
Social Sharing
Search
Articles
Recently Added Jobs
Rajasthan High Court - Jodhpur Recruitment 2017 for Civil Judges
Last Date: 21 December, 2017
Last Date: 21 December, 2017
WBSEDCL Recruitment - 2017 for Office Executive
Last Date: 16 May, 2017
Last Date: 16 May, 2017
RECRUITMENT OF PROBATIONARY OFFICERS IN STATE BANK OF INDIA
Last Date: 06 March, 2017
Last Date: 06 March, 2017
UPSC Combined Medical Services Examination 2015
Last Date: 10 April, 2015
Last Date: 10 April, 2015
UPSC Engineering Services Examination 2015
Last Date: 10 April, 2015
Last Date: 10 April, 2015