1. Basic questions
1. Write the output result of the following program
Copy the code The code is as follows:
$str1 = null;
$str2 = false;
echo $str1==$str2 ? 'Equal' : 'Not equal';
$str3 = ' ';
$str4 = 0;
echo $str3==$str4 ? 'Equal' : 'Not equal';
$str5 = 0;
$str6 = '0';
echo $str5===$str6 ? 'Equal' : 'Not equal';
?>
2. Write the output result of the following program
Copy code The code is as follows:
$a1 = null;
$a2 = false;
$a3 = 0;
$a4 = '';
$a5 = '0';
$a6 = 'null';
$a7 = array();
$a8 = array(array());
echo empty($a1) ? 'true' : 'false';
echo empty($a2) ? 'true' : 'false';
echo empty($a3) ? 'true' : 'false';
echo empty($a4) ? 'true' : 'false';
echo empty($a5) ? 'true' : 'false';
echo empty($a6) ? 'true' : 'false';
echo empty($a7) ? 'true' : 'false';
echo empty($a8) ? 'true' : 'false';
?>
3. Write the output of the following program
Copy code The code is as follows:
$test = 'aaaaaa';
$abc = & $test;
unset($test);
echo $abc;
?>
4. Write the output of the following program
Copy code The code is as follows:
$count = 5;
function get_count(){
static $count = 0;
return $count++;
}
echo $count;
++$count;
echo get_count();
echo get_count();
?>
5. Write the output of the following program
Copy the code The code is as follows:
$GLOBALS['var1'] = 5;
$var2 = 1;
function get_value(){
global $var2;
$var1 = 0;
return $var2++;
}
get_value();
echo $var1;
echo $var2;
?>
6. Write the following program Output result
Copy code The code is as follows:
function get_arr($arr){
unset($arr[0]);
}
$arr1 = array(1, 2);
$arr2 = array(1, 2);
get_arr(&$arr1 );
get_arr($arr2);
echo count($arr1);
echo count($arr2);
?>
7 . Use more than five methods to obtain the extension of a file Requirement: dir/upload.image.jpg, find .jpg or jpg,
must use PHP's own processing function for processing, method It cannot be obviously repeated and can be encapsulated into functions, such as get_ext1($file_name), get_ext2($file_name)
2. Algorithm questions 1. Use PHP to describe bubble sort and quick sort algorithms. The object can be an array
2. Use PHP to describe the sequential search and binary search (also called binary search) algorithms. Sequential search must consider efficiency. The object can be an ordered array
3. Write a two-dimensional array sorting Algorithm functions can be universal and can call PHP built-in functions
[Answer attached] (The answer below is not necessarily the best, just a simple reference)
1. Basic questions
1. Equal equal not equal
2. true true true true true false true false
3. aaaaaa
4. 5 0 1
5. 5 2
6. 1 2
7. Use more than five ways to get the extension of a file
Copy the code The 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), '.')));
}
2. Algorithm questions 1. Use PHP to describe bubble sort With the quick sort algorithm, the object can be an array
Copy code The 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 sorting)
function quick_sort($array) {
if (count($array) <= 1) return $array;
$key = $array[0];
$left_arr = array();
$right_arr = array();
for ($i=1; $iif ($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 . Use PHP to describe sequential search and binary search (also called binary search) algorithms. Sequential search must consider efficiency. The object can be
an ordered array
Copy code The code is as follows:
//Binary search (search for a certain element in the 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;
}
//Sequential search (in the array Find an element)
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 that can be used universally property, you can call the PHP built-in function
Copy the code The code is as follows:
//Two-dimensional array sorting, $ arr is data, $keys is the key value of sorting, $order is the sorting rule, 1 is ascending order, 0 is descending order
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.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320440.htmlTechArticle1. Basic questions 1. Write the output of the following program. Copy the code. The code is as follows: ? $str1 = null; $str2 = false; echo $str1==$str2 ? 'Equal' : 'Not equal'; $str3 = ''; $str4 = 0; ec...