first, the basic problem
1. Write out the output of the following program
Copy CodeThe code is as follows:
$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
Copy CodeThe code is as follows:
$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
Copy CodeThe code is as follows:
$test = ' aaaaaa ';
$ABC = & $test;
Unset ($test);
Echo $abc;
?>
4. Write out the output of the following program
Copy CodeThe code is as follows:
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
Copy CodeThe code is as follows:
$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
Copy CodeThe code is as follows:
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
Copy CodeThe code is as follows:
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
Copy CodeThe code is as follows:
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 lookups and binary lookups (also called binary lookup) algorithms, sequential lookups must consider efficiency, and objects can be
an ordered array
Copy CodeThe code is as follows:
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
Copy CodeThe code is as follows:
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;
}
http://www.bkjia.com/PHPjc/320440.html www.bkjia.com true http://www.bkjia.com/PHPjc/320440.html techarticle first, the basic question 1. Write out the following program output copy code code is as follows:? $STR 1 = null; $str 2 = false; Echo $str 1== $str 2? ' Equal ': ' Not equal '; $str 3 = "; $str 4 = 0; EC ...