Skip to content

Commit a6b51c4

Browse files
authored
Merge pull request xianyunyh#11 from OMGZui/master
补充
2 parents b1de87f + 642dc13 commit a6b51c4

File tree

1 file changed

+66
-5
lines changed

1 file changed

+66
-5
lines changed

面试/笔试题.md

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function getPoint(Node $a,Node $b) {
217217

218218
17、**isset(null) isset(false) empty(null) empty(false)输出**
219219

220-
​ false,false,true,true
220+
​ false,true,true,true[参考](http://php.net/manual/zh/types.comparisons.php)
221221

222222
18、**优化MYSQL的方法**
223223

@@ -391,15 +391,76 @@ type 记录变量的类型。然后根据不同的类型,找到不同的value
391391
![img](01.png)
392392

393393

394-
38、有两个文件文件,大小都超过了1G,一行一条数据,每行数据不超过500字节,两文件中有一部分内容是完全相同的,请写代码找到相同的行,并写到新文件中。PHP最大允许内内为255M。
394+
38、有两个文本文件,大小都超过了1G,一行一条数据,每行数据不超过500字节,两文件中有一部分内容是完全相同的,请写代码找到相同的行,并写到新文件中。PHP最大允许内内为255M。
395+
396+
```php
397+
// 思路:使用协程yield
398+
function readFieldFile($fileName)
399+
{
400+
$fp = fopen($fileName, "rb");
401+
while (!feof($fp)) {
402+
yield fgets($fp);
403+
}
404+
fclose($fp);
405+
}
406+
407+
$file1 = readFieldFile('big1.txt');
408+
$file2 = readFieldFile('big2.txt');
409+
410+
$file1->rewind();
411+
$file2->rewind();
412+
while ($file1->valid() && $file2->valid()) {
413+
if ($file1->current() == $file2->current()) {
414+
file_put_contents('big.txt', $file1->current(), FILE_APPEND);
415+
}
416+
$file1->next();
417+
$file2->next();
418+
}
419+
```
395420

396421
39、请写出自少两个支持回调处理的PHP函数,并自己实现一个支持回调的PHP函数
397422

398-
preg_matacth_callback. call_user_func
423+
preg_match_callback. call_user_func
424+
425+
```php
426+
function myCallBack(Closure $closure, $a, $b)
427+
{
428+
return $closure($a, $b);
429+
}
430+
431+
myCallBack(function ($a, $b) {
432+
return $a + $b;
433+
}, 1, 2);
434+
435+
```
399436

400-
40、请写出自少两个获取指定文件夹下所有文件的方法(代码或思路)。
437+
40、请写出至少两个获取指定文件夹下所有文件的方法(代码或思路)。
438+
439+
```php
440+
// 递归获取,排除.和..,除了文件夹就是文件
441+
function myScanDir($dir)
442+
{
443+
$files = array();
444+
if (is_dir($dir)) {
445+
if ($handle = opendir($dir)) {
446+
while (($file = readdir($handle)) !== false) {
447+
if ($file != "." && $file != "..") {
448+
if (is_dir($dir . "/" . $file)) {
449+
$files[$file] = myScanDir($dir . "/" . $file);
450+
} else {
451+
$files[] = $dir . "/" . $file;
452+
}
453+
}
454+
}
455+
closedir($handle);
456+
return $files;
457+
}
458+
}
459+
}
460+
461+
```
401462

402-
41、请写出自少三种截取文件名后缀的方法或函数(PHP原生函数和自己实现函数均可)
463+
41、请写出至少三种截取文件名后缀的方法或函数(PHP原生函数和自己实现函数均可)
403464

404465
basename expload() strpos
405466

0 commit comments

Comments
 (0)