Question-21. What is the purpose of _METHOD_ constant ?

Answer- _METHOD_ − The class method name. (Added in PHP 5.0.0) The method name is returned as it was declared (case-sensitive).

Question-22. What is the purpose of break statement ?

Answer- break terminates the for loop or switch statement and transfers execution to the statement immediately following the for loop or switch.

Question-23. What is the purpose of continue statement ?

Answer- continue causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.

Question-24. Explain the syntax for ‘foreach’ loop ?

Answer- 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;
}

 

Question-25. What is numeric array ?

Answer- Numeric array − An array with a numeric index. Values are stored and accessed in linear fashion.

Question-26. What is associate array ?

Answer- 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.

Question-27. What is Multidimensional array ?

Answer- Multidimensional array − An array containing one or more arrays and values are accessed using multiple indices.

Question-28. How will you concatenate two strings in PHP? ?

Answer- To concatenate two string variables together, use the dot (.) operator −

$string1="Hello World";
$string2="1234";
echo $string1 . " " . $string2;

This will produce following result −

Hello World 1234

 

Question-29. How will you find the length of a string in PHP ?

Answer- 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 −

12

 

Question-30. How will you locate a string within a string in PHP ?

Answer- 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 −

6