- include与require的区别
<?php
$file = __DIR__ . '/test.file.php';
- 常用数组操作函数
<?php
$array = [];
$array2 = [];
array_push($array, 'abcdef');
var_dump(array_push($array2, false));
$array3 = array_merge($array, $array2);
var_dump(in_array(0, $array3));
var_dump(in_array(0, $array3, true));
var_dump(array_key_exists(1, $array3));
var_dump(array_pop($array3));
var_dump(array_unshift($array3, 'hello'));
var_dump(array_shift($array3));
array_push($array3, rand(1, 100));
array_push($array3, rand(1, 100));
array_push($array3, rand(1, 100));
array_push($array3, rand(1, 100));
array_push($array3, rand(1, 100));
array_push($array3, rand(1, 100));
sort($array3, SORT_NUMERIC);
print_r($array3);
rsort($array3);
print_r($array3);
var_dump(ksort($array3));
print_r($array3);
krsort($array3);
print_r($array3);
natsort($array3);
print_r($array3);
natcasesort($array3);
print_r($array3);
print_r(array_keys($array3));
print_r(array_values($array3));
print_r(array_column($array3, 'name'));
array_column($array3, null, 'name');
print_r($array3);
- 实现发起http请求的方式
<?php
$url = 'https://www.baidu.com';
$content1 = file_get_contents($url);
$data = http_build_query([]);
$options = ['http' => ['method' => 'GET', 'content' => $data,'header' => 'Content-Type:application/x-www-form-urlencoded','timeout' => 30]];
$content2 = file_get_contents($url, false, stream_context_create($options));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content3 = curl_exec($ch);
curl_close($ch);
echo base64_encode($content1);
echo PHP_EOL;
echo base64_encode($content2);
echo PHP_EOL;
echo base64_encode($content3);
- …
在这里插入代码片