Home Interview Questions and Answers PHP Interview Questions and Answers For Freshers part-3

PHP21.What is the purpose of _METHOD_ constant?
_METHOD_ − The class method name. (Added in PHP 5.0.0) The method name is returned as it was declared (case-sensitive).

22.What is the purpose of break statement?
break terminates the for loop or switch statement and transfers execution to the statement immediately following the for loop or switch.

23.What is the purpose of continue statement?
continue causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.

24.Explain the syntax for ‘foreach’ loop.
The foreach statement is used to loop through arrays. For each pass the value of the current array element is assigned to $value and the array pointer is moved by one and in the next pass next element will be processed.

foreach (array as value)
code to be executed;

25.What is numeric array?
Numeric array − An array with a numeric index. Values are stored and accessed in linear fashion.

26.What is associate array?
Associative array − An array with strings as index. This stores element values in association with key values rather than in a strict linear index order.

27.What is Multidimensional array?
Multidimensional array − An array containing one or more arrays and values are accessed using multiple indices.

28.How will you concatenate two strings in PHP?
To concatenate two string variables together, use the dot (.) operator −

$string1=”Hello World”;
echo $string1 . ” ” . $string2;
This will produce following result −

Hello World 1234

29.How will you find the length of a string in PHP?
The strlen() function is used to find the length of a string. Let’s find the length of our string “Hello world!” −

echo strlen(“Hello world!”);
This will produce following result −


30.How will you locate a string within a string in PHP?
The strpos() function is used to search for a string or character within a string. If a match is found in the string, this function will return the position of the first match. If no match is found, it will return FALSE. Let’s see if we can find the string “world” in our string −

echo strpos(“Hello world!”,”world”);
This will produce following result −


You may also like

Leave a Comment