Showing posts with label tips. Show all posts
Showing posts with label tips. Show all posts

Friday, April 9, 2010

asort arsort diffrerences

Question: what is the difference between asort and arsort?

Answer:

asort - sorts an array. It maintains index values.

arsort- It sorts an array in reverse manner.

Example for asort:


<?php
$fruits = array("d" => "php", "a" => "interview", "b" => "questions", "c" => "answers");
asort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>

The output is c = answers a = interview d = php b = questions

Example for arsort:

<?php
$fruits = array("d" => "php", "a" => "interview", "b" => "questions", "c" => "answers");
arsort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>

The output is

b = questions d = php a = interview c = answers

Thursday, April 8, 2010

stristr trick questions

What is output of the following

echo stristr('user@EXAMPLE.com', 'R'); //
echo stristr('user@EXAMPLE.com', 'r'); //

Output

r@EXAMPLE.com
r@EXAMPLE.com

The stristr is case insensitive.

strstr trick questions

What is output of the following

strstr("php@interview",'@');
strstr("php@interview",'@',true);

Answer

@interview
php

This is the mostly asked interview question

substr - related questions

What is substr in php?

substr is used to return a part of a string

Two arguments can be passed to the substr

1. start value
2. length value

Examples
1. start value

substr('interview',1); // returns "nterview"
substr('interview',-2); //returns "ew"

2. Length value

substr('interview',-2,1); //the output is "e"
substr('interview',-3,-2); //the output is "i"
substr('interview',1,2); //the out put is "nt"

Your comment always welcome

Wednesday, April 7, 2010

captcha in php

Question: What is captcha in php

Answer

Captcha is nothing but an image which contains numbers,characters with an distorted background

Acronym for captcha is

Completely Automated Public Turing test to tell Computers and Human Apart

Simply saying : It is a mechanism for protecting spams in an application.






Tuesday, April 6, 2010

Explain Static keyword in php

Answer

Declaring class members or methods as static makes them accessible without needing an instantiation of the class. A member declared as static can not be accessed with an instantiated class object (though a static method can).

Monday, April 5, 2010

what are the magic methods in php

Answer
__construct
__destruct
__call
__callStatic
__get
__set
__isset
__unset
__sleep
__wakeup
__toString
__invoke
__set_state
__clone

These are all the magic methods in php

Sunday, April 4, 2010

what is magic constants in php

Answer
======

Magic constants change their value depending on where they used

Example:
=========

__line__

this will show the current line number.

There are seven magic constants in php

__LINE__
__FILE__
__DIR__
__FUNCTION__
__CLASS__
__METHOD__
__NAMESPACE__

Saturday, April 3, 2010

Question:what is References in php

Question: what is References in php

Answer

Access the same variable content by different names

Example
---------
$x =& $y;
?>
Here the $x,$y point the same content