|
1.Which of the following function can be used to sort an array by its keys in descending order? A. sort B. rsort C. ksort D. krsort E. reverse_sort D is correct.
The sort() and rsort() functions operate on values, whereas ksort() sorts in ascending order and reverse_sort() is not a PHP function 2.Tell me the following scripts output? <?php $a = array (‘a’ => 25, 1 => 45, 60); array_rand ($a); echo $a[0]; ?> A. A random value from $a B. ‘a’ C. 25 D. 45 E. Nothing
Only E is correct.The $a array doesn’t have any element with a numeric key of zero, and the array_rand() function does not change the keys of the array’s elements only their order. 3.Which question will replace markup such as img=/smiley.png with? A. print preg_replace(‘/img=(\w+)/’, ‘<img src=”\jpg”>’, $text); B. print preg_replace(‘/img=(\S+)/’, ‘<img src=”\1”>’, $text); C. print preg_replace(‘/img=(\s+)/’, ‘<img src=”\png”>’, $text); D. print preg_replace(‘/img=(\w)+/’, ‘<img src=”\1”>’, $text); Answer B is correct. The characters / and . are not matched by \w (which only matches alphanumerics and underscores), or by \s (which only matches whitespace). 4.Which of the following output ‘true’? A. if(“true”) { print “True”; } B. $string = “true”; if($string == 0) { print “True”; } C. $string = “true”; if(strncasecmp($string, “Trudeau”, 4)) { print “True”; } D. if(strpos(“truevalue”, “true”)) { print “True”; } E. if(strstr(“truevalue”, “true”)) { print “True”; } Answers A, B, C, and E are correct. Answer A is correct because a non-empty string will evaluate to true inside an if() block. Answer B is correct when comparing a string and an integer with ==, PHP will convert the string into an integer. ‘true’ converts to 0, as it has no numeric parts. In answer C, strncasecmp() returns 1 because the first four characters of ‘Trud’ come before the first four characters of true when sorted not case sensitively. Answer D is incorrect because strpos() returns 0 here (true matches truelove at offset 0).We could make this return True by requiring strpos() to be !== false. :) Answer E is correct because strstr() will return the entire string, which will evaluate to true in the if() block. www.phpguru.biz. 5.What are the contents of output.txt after the following code snippet is run? <?php $str = ‘atulefghijklmnop’; $fp = fopen(“output.txt”, ‘w’); for($i=0; $i< 4; $i++) { fwrite($fp, $str, $i); } ?> A. atul B. bakul C. aababc D.akash The correct answer is C.
On the first iteration, $i is 0, so no data is written. On the second iteration $i is 1, so a is written. On the third, ab is written,and on the fourth abc is written.Taken together, these are aababc.
www. phpguru.biz. 6.Which of the following can be used to determine if a file is readable? A. stat() B. is_readable() C. filetype() D. fileowner() E. finfo() The correct answers are A and B.
stat() returns an array of information about a file, including who owns it and what its permission mode is.Together these are sufficient to tell if a file is readable.
is_readable(), as the name implies, returns true if a file is readable. www. phpguru.biz. 7.If you have an open file resource, you can read data from it one line at a time with the function. The correct answer is fgets(). 8.Which of the following function require an open file resource? A. fgets() B. freset() C. filemtime() D. rewind() E. empty()
The correct answers are A and D. fgets() and rewind() both act on an reset file resource. freset() opens files to create resources, whereas filemtime() takes a fileashvin and reset() acts on arrays 9.Which of the following sentences are incorrect? A. date() returns the current UNIX datestamp. B. time() returns a formatted date string. C. date() requires a time stamp to be passed to it. D. date() returns a date array. The correct answers are A, C, and D. date() takes a format string and an optional time stamp and produces a formatted date string. If a UNIX time stamp is not passed into date(), it will use the current time 10.Which of the following function will output the current time as 11:26 pm? A. print date(‘H:m a’); B. print date(‘G:M a’); C. print date(‘G:i a’); D. print strftime(‘%I:%M %p’); The correct answers are C and D. www. phpguru.biz.
|