PHP MCQ SET


PHP Multiple Choice Question Material
[1] How does the identity operator === compare two values?
(A) => It converts them to a common compatible data type and then compares the resulting values
(B) => It returns True only if they are both of the same type and value
(C) => If the two values are strings, it performs a lexical comparison
Answer =>> It converts them to a common compatible data type and then compares the resulting values

[2] Under what circumstance is it impossible to assign a default value to a parameter while declaring a function?
(A) => When the parameter is Boolean
(B) => When the function is being declared as a member of a class
(C) => When the parameter is being declared as passed by reference
Answer =>> When the parameter is being declared as passed by reference

[3] Variables always start with a ........ in PHP
(A) => Pond-sign
(B) => Yen-sign
(C) => Dollar-sign
Answer =>> Dollar-sign

[4] PHP is an open source software
(A) => True
(B) => False
(C) => None
Answer =>> True

[5] Which of the following is not valid PHP code?
(A) => $_10
(B) => $10_somethings
(C) => ${“MyVar”}
Answer =>> $10_somethings

[6] What is the difference between print() and echo()?
(A) => print() can be used as part of an expression, while echo() can’t
(B) => echo() can be used as part of an expression, while print() can’t
(C) => echo() can be used in the CLI version of PHP, while print() can’t
Answer =>> print() can be used as part of an expression, while echo() can’t

[7] PHP runs on different platforms (Windows, Linux, Unix, etc.)
(A) => True
(B) => False
(C) => None
Answer =>> True

[8] Which of the following will not combine strings $s1 and $s2 into a single string?
(A) => $s1 + $s2
(B) => $s1 + $s2
(C) => mplode(' ', array($s1,$s2))
Answer =>> $s1 + $s2

[9] Given a variable $email containing the string user@example.com, which of the following statements would extract the string example.com?
(A) => substr($email, strpos($email, "@"));
(B) => strchr($email, "@");
(C) => substr($email, strpos($email, "@")+1);
Answer =>> substr($email, strpos($email, "@")+1);

[10] Given a comma-separated list of values in a string, which function from the given list can create an array of each individual value with a single call?
(A) => explode()
(B) => extract()
(C) => strstr()
Answer =>> explode()

[11] What is the best all-purpose way of comparing two strings?
(A) => Using strcmp()
(B) => Using strcasecmp()
(C) => Using the == operator
Answer =>> Using strcmp()

[12] Which of the following PCRE regular expressions best matches the string php|architect?
(A) => [a-z][a-z][a-z]\|\w{9}
(B) => [az]{3}\|[az]{9}
(C) => \d{3}\|\d{8}
Answer =>> [a-z][a-z][a-z]\|\w{9}

[13] Which of the following functions can be used to determine the integrity of a string?
(A) => md5()
(B) => sha1()
(C) => Both
Answer =>> Both

[14] What happens if you add a string to an integer using the + operator?
(A) => The interpreter outputs a type mismatch error
(B) => The string is converted to a number and added to the integer
(C) => The string is discarded and the integer is preserved
Answer =>> The string is converted to a number and added to the integer

[15] The ___________ function can be used to compare two strings using a case-insensitive binary algorithm
(A) => strcmp()
(B) => stricmp()
(C) => strcasecmp()
Answer =>> strcasecmp()

[16] Which of the following functions can be used to convert the binary data stored in a string into its hexadecimal representation?
(A) => pack()
(B) => encode_hex()
(C) => printf()
Answer =>> pack()

[17] ^[A-Za-z].* matches
(A) => its Allows Only Alphabetics
(B) => Its Allow Only Numeric
(C) => None
Answer =>> its Allows Only Alphabetics

[18] ^[0-9]{5}(\-[0-9]{4})?$ matches
(A) => its Allows Only Alphabetics
(B) => Its Allow Only Numeric
(C) => None
Answer =>> Its Allow Only Numeric

[19] Array values are keyed by ______ values (called indexed arrays) or using ______ values (called associative arrays). Of course, these key methods can be combined as well.
(A) => Float, string
(B) => String, Boolean
(C) => Integer, string
Answer =>> Integer, string

[20] Which array function checks if the specified key exists in the array
(A) => array_key_exist()
(B) => array_key_exists()
(C) => array_keys_exists()
Answer =>> array_key_exists()

[21] There are three different kind of arrays:
(A) => Numeric array, String array, Multidimensional array
(B) => Numeric array, Associative array, Dimensional array
(C) => Numeric array, Associative array, Multidimensional array
Answer =>> Numeric array, Associative array, Multidimensional array

[22] Absent any actual need for choosing one method over the other, does passing arrays by value to a read-only function reduce performance compared to passing them by reference?
(A) => No.
(B) => Yes, but only if the array is large.
(C) => Yes, but only if the function modifies the contents of the array.
Answer =>> No.

[23] Assume you would like to sort an array in ascending order by value while preserving key associations. Which of the following PHP sorting functions would you use?
(A) => ksort()
(B) => asort()
(C) => krsort()
Answer =>> asort()

[24] What function computes the difference of arrays?
(A) => array_diff
(B) => diff_array
(C) => arrays_diff
Answer =>> array_diff

[25] What functions count elements in an array?
(A) => count
(B) => Sizeof
(C) => Array_Count
Answer =>> count

[26] What array will you get if you convert an object to an array?
(A) => An array with properties of that object as the array's elements.
(B) => An array with properties of that array as the object's elements.
(C) => An array with properties of that object as the Key elements.
Answer =>> An array with properties of that object as the array's elements.

[27] Which of the following functions retrieve the entire contents of a file in such a way that it can be used as part of an expression?
(A) => file_get_contents()
(B) => fgets()
(C) => fopen()
Answer =>> file_get_contents()

[28] fgets() is used to read a file one line at a time
(A) => True
(B) => False
(C) => None
Answer =>> True

[29] What is the difference between stat() and fstat()?
(A) => While stat() works on open file pointers, fstat() works on files specified by pathname
(B) => While fstat() works on open file pointers, stat() works on files specified by pathname
(C) => fstat() has nothing to do with files
Answer =>> While fstat() works on open file pointers, stat() works on files specified by pathname

[30] flock() is used to unlock a file so that two or more people do not get access to it at the same time.
(A) => True
(B) => False
(C) => None
Answer =>> False

[31] Which of the following functions reads the entire contents of a file?
(A) => fgets()
(B) => file_get_contents()
(C) => fread()
Answer =>> file_get_contents()

[32] What is the purpose of basename() function?
(A) => Returns the last accessed time of the file
(B) => Returns the first accessed time of the file
(C) => Strips of the path and returns the file name.
Answer =>> Strips of the path and returns the file name.

[33] Assuming that image.jpg exists and is readable by PHP, how will the following script be displayed if called directly from a browser?
(A) => As a JPEG image
(B) => As a broken image
(C) => As a JPEG file for download
Answer =>> As a broken image

[34] What should you do if your script is having problem recognizing file endings from a text file saved on a platform different from the one you’re reading it on?
(A) => Change the auto_detect_line_endings INI setting
(B) => Use a regular expression to detect the last letter of a line
(C) => Use fpos()
Answer =>> Change the auto_detect_line_endings INI setting

[35] The ............ function checks if the "end-of-file" (EOF) has been reached.
(A) => feof()
(B) => feofs()
(C) => f_eof()
Answer =>> feof()

[36] The ........... function is used to read a single character from a file.
(A) => fgetc()
(B) => fgets()
(C) => fget()
Answer =>> fgetc()

[37] Which of the following DBMSs do not have a native PHP extension?
(A) => MySQL
(B) => IBM DB/2
(C) => None of the above
Answer =>> None of the above

[38] In PHP in order to access MySQL database you will use:
(A) => mysqlconnect() function
(B) => mysql-connect() function
(C) => mysql_connect() function
Answer =>> mysql_connect() function

[39] Transactions are used to treat sets of SQL statements atomically.
(A) => True
(B) => False
(C) => None
Answer =>> True

[40] SQL is not case sensitive. SELECT is the same as select.
(A) => True
(B) => False
(C) => None
Answer =>> True

[41] Which of the following is not an SQL aggregate function?
(A) => CURRENT_DATE()
(B) => MIN
(C) => MAX
Answer =>> CURRENT_DATE()

[42] What does the DESC keyword do in the following query? SELECT * FROM MY_TABLE WHERE ID > 0 ORDER BY ID, NAME DESC
(A) => It causes the dataset returned by the query to be sorted in descending order
(B) => It causes rows with the same ID to be sorted by NAME in ascending order
(C) => It causes rows with the same ID to be sorted by NAME in descending order
Answer =>> It causes rows with the same ID to be sorted by NAME in descending order

[43] The ............. statement is used to delete a table.
(A) => DROP TABLE
(B) => DELETE TABLE
(C) => REMOVE TABLE
Answer =>> DROP TABLE

[44] What will happen at the end of the following sequence of SQL commands? BEGIN TRANSACTION DELETE FROM MYTABLE WHERE ID=1 DELETE FROM OTHERTABLE ROLLBACK TRANSACTION
(A) => The database will remain unchanged
(B) => The contents of OTHERTABLE will be deleted
(C) => The contents of both OTHERTABLE and MYTABLE will be deleted
Answer =>> The database will remain unchanged

[45] Use the .............. to delete the data inside the table, and not the table itself?
(A) => DROP TABLE
(B) => DELETE TABLE
(C) => TRUNCATE TABLE
Answer =>> TRUNCATE TABLE

[46] Can joins be nested?
(A) => True
(B) => False
(C) => None
Answer =>> True

[47] What function can you use to create your own streams using the PHP stream wrappers and register them within PHP?
(A) => wrapper_register
(B) => stream_wrapper
(C) => stream_wrapper_register
Answer =>> stream_wrapper_register

[48] The windows version of PHP has built-in support for the FTP extension
(A) => True
(B) => False
(C) => None
Answer =>> True

[49] The ftp_mkdir() function creates a directory on the FTP server.
(A) => ftp_mkdir()
(B) => ftp_makekdir()
(C) => ftp_mkdirectory()
Answer =>> ftp_mkdir()

[50] Which of the following operations cannot be performed using the standard ftp:// stream wrapper?
(A) => Reading a file
(B) => Writing a file
(C) => Establishing a stateful connection and changing directories interactively
Answer =>> Establishing a stateful connection and changing directories interactively

[51] What will the following script do?
(A) => A list of the FTP servers on the local network
(B) => The address of the FTP server called “tcp”
(C) => The port associated with the TCP service called “FTP”
Answer =>> The port associated with the TCP service called “FTP”

[52] The ftp_size() function returns the size of a specified file on the FTP server.
(A) => get_ftp_size()
(B) => ftp_file_size()
(C) => ftp_size()
Answer =>> ftp_size()

[53] When dealing with timeout values in sockets, the connection timeout can be changed independently of the read/write time out. Which function must be used for this purpose?
(A) => stream_get_timeout
(B) => stream_set_timeout
(C) => stream_fset_timeout
Answer =>> stream_set_timeout

[54] Which of the following network transports doesn’t PHP support?
(A) => tcp
(B) => udp
(C) => pdc
Answer =>> pdc

[55] The FTP functions are used to ....... files from file servers.
(A) => Open
(B) => Login
(C) => All of the above
Answer =>> All of the above

[56] Which of the following are valid PHP stream transports?
(A) => http
(B) => STDIO
(C) => ftp
Answer =>> STDIO

[57] Which of the following functions do not return a timestamp?
(A) => time()
(B) => date()
(C) => strtotime()
Answer =>> date()

[58] The getdate() function returns
(A) => An integer
(B) => A floating-point number
(C) => An array
Answer =>> An array

[59] .......... Returns the time of sunrise for a given day / location
(A) => datesunrise()
(B) => date_sunrise()
(C) => date-sunrise()
Answer =>> date_sunrise()

[60] What will the following script output?
(A) => 00:00:00
(B) => 12:00:00
(C) => 00:i:00
Answer =>> 00:i:00

[61] ................Checks a date for numeric validity.
(A) => check_date
(B) => verifydate
(C) => checkdate
Answer =>> checkdate

[62] What is the difference, in seconds, between the current timestamp in the GMT time zone and the current timestamp in your local time zone?
(A) => It depends on the number of hours between the local time zone and GMT
(B) => There is no difference
(C) => The two will only match if the local time zone is GMT
Answer =>> There is no difference

[63] You must make a call to ................... to specify what time zone you want calculations to take place in before calling any date functions.
(A) => date_default_timezone_set()
(B) => datedefault_timezone_set()
(C) => date_defaulttimezone_set()
Answer =>> date_default_timezone_set()

[64] What would happen if the following script were run on a Windows server set to Moscow, Russia’s time zone?
(A) => It would output the number 0
(B) => It would output the number -1
(C) => It would output the number 1
Answer =>> It would output the number -1

[65] The ......... function parses an English textual date or time into a Unix timestamp
(A) => strtodate()
(B) => stroftime()
(C) => strtotime()
Answer =>> strtotime()

[66] ................ Formats a local time or date according to locale settings.
(A) => strftime
(B) => strgtime
(C) => strhtime
Answer =>> strftime

[67] A script is a
(A) => Program or sequence of instructions that is interpreted or carried out by processor directly
(B) => Program or sequence of instruction that is interpreted or carried out by another program
(C) => Program or sequence of instruction that is interpreted or carried out by web server only
Answer =>> Program or sequence of instruction that is interpreted or carried out by another program

[68] When compared to the compiled program, scripts run
(A) => Faster
(B) => Slower
(C) => The execution speed is similar
Answer =>> Slower

[69] PHP is a widely used ________. scripting language that is especially suited for web development and can be embedded into html
(A) => Open source general purpose
(B) => Proprietary general purpose
(C) => Open source special purpose
Answer =>> Open source general purpose

[70] Which of the following is not true?
(A) => PHP can be used to develop web applications.
(B) => PHP makes a website dynamic.
(C) => PHP can not be embedded into html.
Answer =>> PHP can not be embedded into html.

[71] Which of the following variables is not a predefined variable?
(A) => $get
(B) => $ask
(C) => $request
Answer =>> $ask

[72] You can define a constant by using the define() function. Once a constant is defined
(A) => It can never be changed or undefined
(B) => It can never be changed but can be undefined
(C) => It can be changed but can not be undefined
Answer =>> It can never be changed or undefined

[73] Which of the following function returns the number of characters in a string variable?
(A) => count($variable)
(B) => len($variable)
(C) => strlen($variable)
Answer =>> strlen($variable)

[74] When you need to obtain the ASCII value of a character which of the following function you apply in PHP?
(A) => chr( );
(B) => asc( );
(C) => ord( );
Answer =>> ord( );

[75] A variable $word is set to �HELLO WORLD�, which of the following script returns in title case?
(A) => echo ucwords($word)
(B) => echo ucwords(strtolower($word)
(C) => echo ucfirst($word)
Answer =>> echo ucwords(strtolower($word)

[76] The difference between include() and require()
(A) => are different how they handle failure
(B) => both are same in every aspects
(C) => is include() produced a Fatal Error while require results in a Warning
Answer =>> are different how they handle failure

[77] When a file is included the code it contains, behave for variable scope of the line on which the include occurs
(A) => Any variable available at that line in the calling file will be available within the called file from that point
(B) => Any variable available at that line in the calling file will not be available within the called file
(C) => Variables are local in both called and calling files
Answer =>> Any variable available at that line in the calling file will be available within the called file from that point

[78] Which of the following method sends input to a script via a URL?
(A) => Get
(B) => Post
(C) => Both
Answer =>> Get

[79] Which of the following method is suitable when you need to send larger form submissions?
(A) => Get
(B) => Post
(C) => Both Get and Post
Answer =>> Post

[80] Which of the following mode of fopen() function opens a file only for writing. If a file with that name does not exist, attempts to create anew file. If the file exist, place the file pointer at the end of the file after all other data.
(A) => W
(B) => W+
(C) => A
Answer =>> A

[81] The function setcookie( ) is used to
(A) => Enable or disable cookie support
(B) => Declare cookie variables
(C) => Store data in cookie variable
Answer =>> Store data in cookie variable

[82] To work with remote files in PHP you need to enable
(A) => allow_url_fopen
(B) => allow_remote_files
(C) => both of above
Answer =>> allow_url_fopen

[83] How would you add 1 to the variable $count?
(A) => incr count;
(B) => $count++;
(C) => $count =+1
Answer =>> $count++;

[84] Father of PHP?
(A) => Larry Wall
(B) => Rasmus Lerdorf
(C) => James Gosling
Answer =>> Rasmus Lerdorf