First, the basic question 1. Write the output of the following program
$STR 1 = null;
$str 2 = false;
echo $str 1== $str 2? ' Equal ': ' Not equal ';
$str 3 = ";
$str 4 = 0;
Echo $str 3== $str 4? ' Equal ': ' Not equal ';
$str 5 = 0;
$str 6 = ' 0′;
echo $str 5=== $str 6? ' Equal ': ' Not equal ';
?>
2. Write out the output of the following program
$a 1 = null;
$a 2 = false;
$a 3 = 0;
$a 4 = ";
$a 5 = ' 0′;
$a 6 = ' null ';
$a 7 = array ();
$a 8 = Array (array ());
echo empty ($a 1)? ' True ': ' false ';
echo Empty ($a 2)? ' True ': ' false ';
echo Empty ($a 3)? ' True ': ' false ';
echo Empty ($a 4)? ' True ': ' false ';
echo Empty ($a 5)? ' True ': ' false ';
echo Empty ($a 6)? ' True ': ' false ';
echo Empty ($a 7)? ' True ': ' false ';
echo empty ($a 8)? ' True ': ' false ';
?>
3. Write out the output of the following program
$test = ' aaaaaa ';
$ABC = & $test;
Unset ($test);
Echo $abc;
?>
4. Write out the output of the following program
function get_count () {
static $count = 0;
return $count + +;
}
Echo $count;
+ + $count;
Echo get_count ();
Echo get_count ();
?>
5. Write out the output of the following program
$GLOBALS [' var1 '] = 5;
$var 2 = 1;
function Get_value () {
Global $var 2;
$var 1 = 0;
return $var 2++;
}
Get_value ();
echo $var 1;
echo $var 2;
?>
6. Write out the output of the following program
function Get_arr ($arr) {
unset ($arr [0]);
}
$arr 1 = Array (1, 2);
$arr 2 = Array (1, 2);
Get_arr (& $arr 1);
Get_arr ($arr 2);
echo Count ($arr 1);
echo Count ($arr 2);
?>
7. Get the extension of a file using more than five different ways
Requirements: dir/upload.image.jpg, find. jpg or JPG,
Must be handled using PHP's own processing function, which cannot be significantly duplicated and can be encapsulated into functions such as GET_EXT1 ($file _name), get_ext2 ($file _name)
Second, the algorithm problem
1. Using PHP to describe the bubble sort and quick sort algorithm, an object can be an array
2. Using PHP to describe order lookup and binary lookup (also called binary lookup) algorithm, sequential lookup must consider efficiency, an object can be an ordered array
3. Write a two-dimensional array sorting algorithm function, which can be universal, call PHP built-in functions
"With Answer" (The following answer is not necessarily the best, just a simple reference)
First, the basic problem
1. Equality and equality are not equal
2. True True True True false
3. aaaaaa
4.5 0 1
5.5 2
6.1 2
7. Get the extension of a file using more than five different ways
function Get_ext1 ($file _name) {
Return STRRCHR ($file _name, '. ');
}
function get_ext2 ($file _name) {
Return substr ($file _name, Strrpos ($file _name, '. '));
}
function Get_ext3 ($file _name) {
Return Array_pop (Explode ('. ', $file _name));
}
function Get_ext4 ($file _name) {
$p = PathInfo ($file _name);
return $p [' extension '];
}
function Get_ext5 ($file _name) {
Return Strrev (substr (Strrev ($file _name), 0, Strpos (strrev ($file _name), '. '));
}
Second, the algorithm problem
1. Using PHP to describe the bubble sort and quick sort algorithm, an object can be an array
Bubble sort (Array sort)
function Bubble_sort ($array)
{
$count = count ($array);
if ($count <= 0) return false;
for ($i =0; $i < $count; $i + +) {
for ($j = $count-1; $j > $i; $j?) {
if ($array [$j] < $array [$j-1]) {
$tmp = $array [$j];
$array [$j] = $array [$j-1];
$array [$j-1] = $tmp;
}
}
}
return $array;
}
Quick sort (Array sort)
function Quick_sort ($array) {
if (count ($array) <= 1) return $array;
$key = $array [0];
$left _arr = Array ();
$right _arr = Array ();
for ($i =1; $i
if ($array [$i] <= $key)
$left _arr[] = $array [$i];
Else
$right _arr[] = $array [$i];
}
$left _arr = Quick_sort ($left _arr);
$right _arr = Quick_sort ($right _arr);
Return Array_merge ($left _arr, Array ($key), $right _arr);
}
2. Using PHP to describe order lookup and binary lookup (also called binary lookup) algorithm, sequential lookup must consider efficiency, an object can be an ordered array
Binary lookup (Find an element in an array)
function Bin_sch ($array, $low, $high, $k) {
if ($low <= $high) {
$mid = Intval (($low + $high)/2);
if ($array [$mid] = = $k) {
return $mid;
}elseif ($k < $array [$mid]) {
Return Bin_sch ($array, $low, $mid-1, $k);
}else{
Return Bin_sch ($array, $mid +1, $high, $k);
}
}
return-1;
}
Order lookup (Find an element in an array)
function Seq_sch ($array, $n, $k) {
$array [$n] = $k;
for ($i =0; $i < $n; $i + +) {
if ($array [$i]== $k) {
Break
}
}
if ($i < $n) {
return $i;
}else{
return-1;
}
}
3. Write a two-dimensional array sorting algorithm function, which can be universal, call PHP built-in functions
Two-dimensional array sorting, $arr is the data, $keys is the sort of health value, $order is the collation, 1 is ascending, 0 is descending
function Array_sort ($arr, $keys, $order =0) {
if (!is_array ($arr)) {
return false;
}
$keysvalue = Array ();
foreach ($arr as $key = = $val) {
$keysvalue [$key] = $val [$keys];
}
if ($order = = 0) {
Asort ($keysvalue);
}else {
Arsort ($keysvalue);
}
Reset ($keysvalue);
foreach ($keysvalue as $key = = $vals) {
$keysort [$key] = $key;
}
$new _array = Array ();
foreach ($keysort as $key = = $val) {
$new _array[$key] = $arr [$val];
}
return $new _array;
}
A PHP face Test (with answer)
2007-06-25 10:36
The test is very basic, but the foundation is not strong, there is a group will not do. Like in HTTP 1.0, the meaning of status code 401, error_reporting (2047) These do not know. But with 2047 seems a bit perverted, too hard to read.
If you can refer to the manual ~ ~
* 1. In PHP, the name of the current script (not including the path and query string) is recorded in the predefined variable (1), while the URL linked to the current page is recorded in the predefined variable (2).
2. The execution of the program segment outputs (3).
3. In HTTP 1.0, the meaning of status code 401 is (4); If you return a prompt for "file not found", the header function is available with the statement (5).
4. The function of array function Arsort is (6); the function of statement error_reporting (2047) is (7).
The database connection string format in 5.PEAR is (8).
6. Write a regular expression that js/vbs all the scripts on the Web page (that is, remove the script tag and its contents): (9).
7. Install PHP in the Apache module, and in the file http.conf, the PHP module should be loaded dynamically with the statement (10).
Then use the statement (11) so that Apache will all files with the extension PHP as PHP script processing.
8. Statements include and require can include another file in the current file, the difference is (12), in order to avoid multiple inclusion of the same file, you can use the statement (13) instead of them.
9. The properties of the class can be serialized and saved to the session so that the entire class can be restored later, and the function to be used is (14).
10. The argument of a function cannot be a reference to a variable unless (15) is set to on in PHP.ini.
The meaning of the left join in 11.SQL is (16).
If Tbl_user records the student's name and school Number (ID),
Tbl_score recorded student (ID) and test scores (score) and test subjects (subject), which were expelled from the school after the exam,
To print out each student's name and the corresponding total, the SQL statement (17) can be used.
12. In PHP, Heredoc is a special string, and its end flag must be (18).
13. Write a function that can traverse all the files and subfolders under a folder.
14. Briefly describe the implementation principle of infinite classification in the forum.
15. Design a Web page so that it pops up a full-screen window with a text box and a button. The user clicks the button to close the window while entering the information in the text box, and the input information is displayed on the main page.
Answer (fill in the blanks):
1. Echo $_server[' php_self '; echo $_server["Http_referer"];
2.0
3. (4) Unauthorized (5) header ("http/1.0 404 Not Found");
4. (6) Reverse-order the array and keep the index relationship (7) all errors and warnings
5. I didn't get it.
6./ ].*?>.*?<\/script>/si
7. (LoadModule) php5_module "D:/xampp/apache/bin/php5apache2.dll"
(one) AddType application/x-httpd-php-source. Phps
AddType application/x-httpd-php. php. php5. PhP4. php3. phtml
8. (12) When an exception occurs, the include generates a warning require a fatal error (require_once ()/include_once ()
9. Serialize ()/unserialize ()
Ten. Allow_call_time_pass_reference
11. (16) Natural left outer connection
Select Name, count (score) as Sum_score from Tbl_user left join Tbl_score on Tbl_user.id=tbl_score.id GROUP by Tbl_us Er.id
12. The line where the end identifier is located cannot contain any other characters except ";"
13.
/**
* Traversing the directory, the result is stored in an array. Support PHP4 and above. PHP5 can replace the while loop with the Scandir () function later.
* @param string $dir
* @return Array
*/
function My_scandir ($dir)
{
$files = Array ();
if ($handle = Opendir ($dir)) {
while (($file = Readdir ($handle))!== false) {
if ($file! = ":" && $file! = ".") {
if (Is_dir ($dir. “/” . $file)) {
$files [$file] = Rec_scandir ($dir. “/” . $file);
}else {
$files [] = $file;
}
}
}
Closedir ($handle);
return $files;
}
}