Skip to content

Instantly share code, notes, and snippets.

@flashvnn
Created June 28, 2014 13:41
Show Gist options
  • Select an option

  • Save flashvnn/f97a247c8c741456ef59 to your computer and use it in GitHub Desktop.

Select an option

Save flashvnn/f97a247c8c741456ef59 to your computer and use it in GitHub Desktop.
Note
Which is not valid PHP code?
(5 scores)
$10_somethings
$_10
${"MyVar"}
$aVaR
(Number of correct answers: 1)
What will be shown after executing the following script?
define("myvalue", "10");
$myarray[10] = "Dog";
$myarray[] = "Human";
$myarray['myvalue'] = "Cat";
$myarray["Dog"] = "Cat";
print "The value is: ";
print $myarray[myvalue]."\n";
(5 scores)
The value is: Dog
The value is: Cat
The value is: Human
The value is: 10
Dog
(Number of correct answers: 1)
What will be the value of the $j variable after executing the following script?
<?php
$a = 10;
$b = 20;
$c = 4;
$d = 8;
$e = 1.0;
$f = $c + $d * 2;
$g = $f % 20;
$h = $b - $a + $c + 2;
$i = $h << $c;
$j = $i * $e;
(5 scores)
256
42
242.0
128
342
(Number of correct answers: 1)
What should be the value of $a, $b and $c variables to print the Hello World string?
<?php
$string = "Hello, World!";
$a = ?;
$b = ?;
$c = ?;
if($a) {
if($b && !$c) {
echo "Goodbye Cruel World!";
} else if(!$b && !$c) {
echo "Nothing here";
}
} else {
if(!$b) {
if(!$a && (!$b && $c)) {
echo "Hello, World!";
} else {
echo "Goodbye World!";
}
} else {
echo "Not quite.";
}
}
?>
(5 scores)
True, True, True
True, True, False
True, True, True
False, False, True
(Number of correct answers: 1)
What will be the output of the following code? Suppose that you call the script with this URL: testscript.php?c=25
<?php
function process($c, $d = 25)
{
global $e;
$retval = $c + $d - $_GET['c'] - $e;
return $retval;
}
$e = 10;
echo process(5);
?>
(5 scores)
-5
5
25
10
0
(Number of correct answers: 1)
How can you connect to the MySQL server if you want to use the new features of MySQL (like: support for prepared statements, support for transactions)?
(5 scores)
mysql_connect("localhost", "user", "password");
mysql_open("localhost", "user", "password");
mysqli_connect("localhost", "user", "password");
connect_mysql("localhost", "user", "password");
(Number of correct answers: 1)
How can you increment the value of the $counter variable by 1?
(5 scores)
$counter++;
$counter =+ 1;
$counter =+ $counter + 1;
$counter += $counter + 1;
++$counter;
(Number of correct answers: 2)
What is the output of the following script?
<?php
$string = 'apple';
$sum = 0;
for ($i = 0;$i < strlen($string);$i++ ){
if ($string[$i] != 'a') {
$sum = $sum + 1;
}
}
echo $sum;
?>
(5 scores)
4
2
3
5
6
(Number of correct answers: 1)
What is the output of the following code?
$a = 1;
$b = 2;
echo ($a + $b == 3) ? 4 : 5;
(5 scores)
4
1
2
3
5
(Number of correct answers: 1)
What is the output of the following script in PHP 5.3:
<?php
$name = 'Peter';
$a = 1;
$b = 2;
$str = <<<'FOO'
My name is: '$name' The result is: "$a + $b"
FOO;
echo $str;
?>
(5 scores)
My name is: '$name' The result is: "$a + $b"
My name is: Peter The result is: "$a + $b"
My name is: '$name' The result is: 3
My name is: Peter The result is: 3
(Number of correct answers: 1)
In PHP an array can be treated as a:
-list
-stack
-queue
-tree
-hash table
(5 scores)
True
False
(Number of correct answers: 1)
We have the following data structure in MySQL 5.1
CREATE TABLE posts (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
);
Insert, update and delete will be frequently used. Which statement is true?
(5 scores)
InnoDB table type is required for this table structure
MyISAM table type is required for this table structure
InnoDB is suggested to get the best performance
The id attribute must be indexed the get a better performance
(Number of correct answers: 1)
<?php
$name = 'Peter';
$a = 1;
$b = 2;
$str = <<<'FOO'
My name is: '$name' The result is: "$a + $b"
FOO;
echo $str;
?>
In PHP an array can be treated as a:
-list
-stack
-queue
-tree
-hash table
(5 scores)
True
False
(Number of correct answers: 1)
We have the following data structure in MySQL 5.1
CREATE TABLE posts (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
);
Insert, update and delete will be frequently used. Which statement is true?
(5 scores)
InnoDB table type is required for this table structure
MyISAM table type is required for this table structure
InnoDB is suggested to get the best performance
The id attribute must be indexed the get a better performance
What will happen after the following SQL statements?
BEGIN TRANSACTION
DELETE FROM MYTABLE WHERE ID=1
TRUNCATE TABLE OTHERTABLE
ROLLBACK TRANSACTION
(5 scores)
It will erase all of the rows in the OTHERTABLE
It will erase all of the rows in the OTHERTABLE and MYTABLE
It will erase all of the rows in the OTHERTABLE and remove one row from the MYTABLE
None of the rows will be deleted
Consider the query below.
SELECT firstname, lastname
FROM test.members
/* Missing part*/;
What should be the missing part to get the following result?
+-----------+----------+
| firstname | lastname |
+-----------+----------+
| Peter | Williams |
| Joe | Smith |
| Peter | Smith |
| George | Jones |
| Joe | Jones |
| Peter | Johnson |
+-----------+----------+
(5 scores)
ORDER BY firstname, lastname DESC
ORDER BY lastname, firstname
ORDER BY lastname ASC, firstname
ORDER BY lastname DESC, firstname
Consider the following query:
SELECT firstname, /* A */
FROM `test`.`members
/* B */;
What should instaed of the comments to get the output below. It lists the last names with the common first name.
+-----------+--------------------------------------+
| common firstnames | list of the lastnames |
+-----------+--------------------------------------+
| George | Jones |
| Joe | Jones,Smith |
| Peter | Smith,Johnson,Williams |
+-----------+--------------------------------------+
(5 scores)
A = group_concat(lastname), B = GROUP BY firstname
A = lastname, B = GROUP BY firstname
A = concat(',', lastname), B = firstname
A = group_concat(firstname), B = GROUP BY lastname
A = firstname, B = GROUP BY lastname
A = concat(',', firstname), B = lastname
What is the differencee between DELETE FROM table_a and TRUNCATE table_b;
(5 scores)
The TRUNCATE will also drop the table structure
The TRUNCATE will reset the auto-increment
The DELETE is faster
The TRUNCATE is faster
The DELETE will also drop the foreign constraints
(Number of correct answers: 2)
Reverse Words
Write a program that reverse the words of the input sentences.
Input format
Number of sentences < 100 000
Each line contains one sentence. The input sentences contain only the letters of the English alphabet (small and upper case) and space. Each word separated by one space. The maximum length of a line is 10 000 character.
Output format:
Reverse the words of the input sentences. Pay attention and do not leave space after the last word. Ignore the empty lines.
Example input:
Hello World
lorem ipsum
Example output
World Hello
ipsum lorem
Sum the primes
Write a code to sum the first 'k' prime number. For example: if 'k' is three: 2 + 3 + 5 = 10.
Input format:
Each line contains one number (k). The number of the lines is less than 1000.
'k' is an integer and 'k' <= 5000.
Output format:
Each line contains the sum of the first 'k' prime number.
Example input:
100
100
101
1000
Example output
24133
24133
24680
3682913
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment