ExamVeda
Login
Home
11
Which one of the following PHP functions can be used to build a function that accepts any number of arguments?
Discuss
Answer & Solution
Answer: Option B
Solution:
Here is an example-
<?php
function foo()
{
      $args = func_get_args();
      foreach ($args as $k => $v)
      { 
           echo "arg".($k+1).": $vn";  
      }
}
foo();
/* will print nothing */
 
foo("Hello");
/* will print Hello */
 
foo("Hello","World","Bye");
/* will print Hello World Bye */
?>
12
Which one of the following PHP functions can be used to find files?
Discuss
Answer & Solution
Answer: Option A
Solution:
Here is an example-
// get all php files AND txt files
$files = glob('*.{php,txt}', GLOB_BRACE);  
print_r($files);  
/* output looks like: 
Array 
    ( 
        [0] => phptest.php 
        [1] => pi.php 
        [2] => post_output.php
        .
        .
        .
)
13
Which of the following PHP functions can be used to get the current memory usage?
Discuss
Answer & Solution
Answer: Option C
Solution:
We can use the memory_get_usage() function, and to get the highest amount of memory used at any point, we can use the memory_get_peak_usage() function.
14
Which of the following PHP functions can be used for generating unique id’s?
Discuss
Answer & Solution
Answer: Option A
Solution:
Many people use the md5() function for this, even though it’s not exactly meant for this purpose. uniqueid() is the function that is to be used.
15
Which one of the following functions can be used to compress a string?
Discuss
Answer & Solution
Answer: Option D
Solution:
We will be able to achieve almost 50% size reduction using this function. The gzuncompress() function is used to uncompress the string.
16
What will be the output of the following PHP code?
<?php
    echo "chr(52)";
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The chr() function returns a character from the specified ASCII value. Since the ASCII value of 4 is 52, thus 4 was displayed.
17
What will be the output of the following PHP code?
<?php
    echo ord ("hi");
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The ord() function returns the ASCII value of the first character of a string. The ASCII value of h is 104, thus 104 was displayed.
18
What will be the output of the following PHP code?
<?php
$str = "Hello World"
echo wordwrap($str,5,"n");    
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
The wordwrap() function wraps a string into new lines when it reaches a specific length.
19
What will be the output of the following PHP code?
<?php
echo ucwords("i love my country");
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The ucwords() function converts the first character of each word in a string to uppercase.
20
What will be the output of the following PHP code?
<?php
echo lcfirst("welcome to India");
?>
Discuss
Answer & Solution
Answer: Option A
Solution:
The lcfirst() function converts the first character of a string to lowercase.