php函数extract、set_time_limit、compact、http_build_query的使用

#extract

PHP extract() 函数从数组中把变量导入到当前的符号表中。

<?php
$a = 'Original';
$my_array = array("a" => "Cat","b" => "Dog", "c" => "Horse");
extract($my_array);
echo "\$a = $a; \$b = $b; \$c = $c";
?>
输出:

$a = Cat; $b = Dog; $c = Horse

#set_time_limit:

运行后会在运行文件的同级目录生成如:1.txt、2.txt、3.txt等文件,直到点击 stop 生成 stop.txt后才停止。

<?php
	set_time_limit(0); //作为无限制脚本
	
	echo '<a href="?stop=1">STOP</a>';
	
	if (isset($_GET['stop'])){
		$filename = "stop.txt";
		fopen($filename, "w");
	}
	
	$b = true;
	$i = 0;
	
	
	do{
		$i ++;
		$filename = $i . ".txt";
		$stopfile = "stop.txt";
		
		if (file_exists($stopfile)){
			exit();
		}
	
		@fopen($filename, ‘w’);
		@file_put_contents($filename, $i);
		sleep(3);
	} while ($b);
?>	

#compact

<?php 
	$firstname = "phpbox.cn"; 
	$lastname = "tong"; 
	$age = "38"; 
	$result = compact("firstname", "lastname", "age"); 
	
	echo "<pre>";
	print_r($result); 
?>
运行结果:
Array
(
    [firstname] => phpbox.cn
    [lastname] => tong
    [age] => 38
)

#http_build_query

<?php
    $data = array(
        'domain'=>'www.phpbox.cn', 
        'site'=>'phpbox', 
        'name'=>'feige'
    ); 
        
    echo http_build_query($data); 
?>
运行结果:
domain=www.phpbox.cn&site=phpbox&name=feige

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值