文档章节

php基础练习1

 小蟲
发布于 2016/07/04 16:15
字数 3080
阅读 59
收藏 0
<!-- 重复输出星号 -->
	<?php
		define("MAX_LINK_NUM",4);
		$title = "<h1>Hello,PHP World!</h1>\n";

		echo $title;

		//循环输出星号
		echo "<pre>\n";
		for($i=1;$i<=MAX_LINK_NUM;$i++)
		{
			echo print_star($i);
			echo "\n";
		}
		echo "</pre>\n";

		function print_star($num)
		{
			return str_repeat("*",$num);
		}
	?>
<?php
//定界符
/*
	定界符"<<<"的后面紧接着的是定界标示符。
	标识符由字母、数字、下划线构成,并且不能以数字开始,结尾的标识符必须顶格书写,其前不能有任何其他的字符。
	通常的错误是将结尾的定界标识符进行缩进。
	定界符中的字符串可以被解析,可以使用转义字符,但不必转义引号。
*/
	$string = <<<EOD
		Example of string spanning multiple lines,
		such as "Tom's house",
		using heredoc syntax.
EOD;
	echo <<< EOT
		There is some string here
		$string
EOT;
?>
<?php
	//数组
	$key = 7;
	$my_stuff = array(
		1,//0=>1
		'abc',//1=>'abc'
		'book' => 'Master PHP',//以字符串为键名
		13 => 'a bad number',//以数字为键名
		"Children's Day" => 6.1,//另一个字符串为键名的元素
		$key => 'a dynamic key',//键名是可以变化的
		'what is the key here'//14 => 'What is the key here?'
	);
	var_dump($my_stuff);
	print_r($my_stuff);
?>
<?php
	//对象的创建
	class Cat{
		var $name;
		var $weight = 0;

		//构造器,创建一个是实例
		function Cat($name)
		{
			$this -> name = $name;
			$this -> weight = 1.5;
		}
		//觅食方法,这时,体重将增加
		function eat($food)
		{
			$this -> weight += $food;
		}
	}
	$cat = new Cat("Tom");
	$cat -> eat(0.5);
	print_r($cat);
	/*输出内容,weight增加了,变成了2千克
	Cat Object(
		[name] => Tom;
		[weight] => 2;
	)
*/
?>
<?php
	//查看数据类型
	var_dump(1.2);
	echo gettype(3.14);
	//强制类型转换
	$str = '123abc';
	$int = (int) $str;//=>类型被下面代码覆盖执行
	$arr = settype($int,'array');
	var_dump($str);
	var_dump($int);
	var_dump($arr);
	echo "<hr/>";
	//更为详细的转换函数
	$str1 = "123.4abc";
	$int1 = intval($str1);
	$flo = floatval($str1);
	$str1 = strval($flo);
	var_dump($str1);
	var_dump($int1);
	var_dump($flo);
	var_dump($str1);
	echo "<hr/>";
	//指定浮点数的精度
	$foo = sprintf("%0.2f",3.1415826);
	$foo = (float) sprintf("%0.2f",3.1415826);
	var_dump($foo);
	echo "<hr/>";
	//浮点型和整型数据间的转化
	$real_num = 3.1e9;
	echo $real_num;
	echo (int) $real_num;
	echo "<hr/>";
	//字符串和数字间的转化
	$number = intval("5.6abc");
	$number = (float) "+5.6abc";
	$number = floatval("-1.2e3f4g5");
	var_dump($number);
	echo "<hr/>";
	$result = "12.3xy45" - 6;
	$result = "xy1234" / 5;
	$result = "1.2.3.4" * 5;
	$result = 1 + "-1.3e3";
	var_dump($result);
	echo "<hr/>";
	//获得资源的类型
	$fp = fopen("foo","w");
	echo get_resource_type($fp);
	echo "<hr/>";
	//数组
	$arr_cat = (array) $cat;
	$arr_cat = array(
		"name" => "Tom",
		"weight" => 2
	);
	var_dump($arr_cat);
?>

表单post方法

html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>表单POST方法</title>
</head>
<body>
	<form action="register.php" method="POST">
		用户账号:<input type="text" name="username"/><br/>
		用户密码:<input type="text" name="password"/><br/>
		电子邮件地址:<input type="text" name="email"/><br/>
		<input type="submit" name="submit" value="注册"/><br/>
	</form>
</body>
</html>

提交到页面

<?php
	/*可以进行一些更深的操作,如数据效验,此处略去*/
?>
<pre>
	您的账号是:<?php echo $_POST['username']; ?>
	您的密码是:<?php echo $_POST['password']; ?>
	电子邮箱是:<?php echo $_POST['email']; ?>
</pre>
<?php
	//检查常量
	if(defined("M_EULER"))
	{
		define("M_EULER",0.57721566490156);
	}
	//检查变量
	if(isset($_GET["page"]))
	{
		$_GET["page"] = 1;
	}
?>
<?php
	//三目运算 等同if判断
	//$condition ? $true_item : $false_item;
	
	//自加自减
	$x = 15;
	echo $x++."&nbsp;";//输出15,先返回后自加
	$y = 20;
	echo ++$y."&nbsp;";//输出21,先自加再返回

	/*此时 $x = 16,$y = 21*/	
	
	echo $x."&nbsp;";

	$z = $x + $y;

	$z1 =$z--;
	echo $z1."&nbsp;";//输出37,先返回后自减

	$z2 = --$z;
	echo $z2."&nbsp;";//输出35,先自减再返回
?>	
<?php
	/*--字符串运算--*/
	$title = "按钮";
	$question = "这是一个复杂的按钮么?";

	//方法1:
	// $button = "<input type=\"button\" value=\"".$title."\" onClick=\"javascript:confirm('".$question."')\"/>";

	//方法2:
	$button = '<input type="button" value="'.$title.'" onClick="javascript:confirm(\''.$question.'\');"/>';

	echo $button;
	/*
		输出内容
		<input type="button" value="按钮" onClick="javascript:confirm('这是一个复杂的按钮么?')"/>;
	*/
?>	
<?php
	//字符串连接
	$var = 89;
	$key = 11;
	$var++;
	echo $var."&nbsp;";
	$var+=$key;
	echo $var."&nbsp;";
	$var*=$key;
	echo $var."&nbsp;";

	$sit="您好";
	$sit .="111!";
	//echo $sit;
	$sit .="222!";
	//echo $sit;
	$sit .="333!";
	echo $sit;
?>		
<?php
	//管理权限
	define("PUBLIC_ARTICLE",1);//发行文章
	define("CREATE_ARTICLE",2);//添加文章
	define("MODIFY_ARTICLE",4);//修改文章
	define("DELETE_ARTICLE",8);//删除文章
	define("SHARCH_ARTICLE",16);//搜索文章
	define("CREATE_COMMENT",32);//添加文章评论
	define("DELETE_COMMENT",64);//删除文章评论

	//所有权限
	$final_allow = PUBLIC_ARTICLE | CREATE_ARTICLE | MODIFY_ARTICLE | DELETE_ARTICLE | SHARCH_ARTICLE | CREATE_COMMENT | DELETE_COMMENT;
	echo "管理者拥有的全部权限:".decbin($final_allow)."<br/>";
	$no_shearch_allow = $final_allow ^ SHARCH_ARTICLE;
	echo "仅无法搜索文章的权限:".decbin($final_allow)."<br/>";
	//编辑人员独有的权限
	$editor_allow = PUBLIC_ARTICLE | MODIFY_ARTICLE | DELETE_ARTICLE;
	$no_editor_allow = $final_allow & ~$editor_allow;
	echo "非编辑人员所有的权限:".decbin($no_shearch_allow)."<br/>";
?>	
<?php
	//条件运算符
	$str = "123";
	var_dump($str == 123);
	var_dump($str == true);
	var_dump($str != null);

	$zero = "0";
	var_dump($zero == true);
	var_dump($zero == false);
	var_dump("0" == 0);
	var_dump("0" == null);
	var_dump(0 == null);
	var_dump("0" === 0);
	var_dump(TRUE === true);
	var_dump(10/2.0 !== 5);
	echo "<hr/>";
	/*$a = 1;
	$b = 5;
	if(a || $b = 5)
	{

	}
	echo "<br/>";
	echo $b;*/
	if(!$a = rand (1,0))
	{
		echo $a;
	}
	if(($a = rand (1,0))==false)
	{
		echo $a;
	}
?>
<?php
	//条件控制

	//这里用$x,$y,$z表示三张牌的点数,如$x=10,$y=5,$z=6
	//用$money代表游戏者的手中的资金
	/*$x = 1;
	$y = 10;
	$z = 10;
	$money = $x+$y+$z;
	if($x+$y+$z == 21)
	{
		$money ++;
		echo "Bingo!You are the WINNER.<br/>";
	}else{
		$money --;
		echo "Sorry!You are a LOSER.<br/>";
	}*/
	/*if($x>$y)
	{
		echo "$x大于$y";
	}else if($x<$y)
	{
		echo "$x小于$y";
	}else{
		echo "$x等于$y";
	}*/

	//$result = ($divisor == 0) ? 0 : $dividend / $divisor;
	/*if($divisor == 0)
		$resule = 0;
	else
		$result = $dividend / $divisor;
	echo $result;*/

	/*switch (Variable)
	{
		case Value1:
			Statement 1;
			break;
		case Value2:
			Statement 2;
			break;
			//......
		default:
			Default Statement;
	}*/
	/*$char = "p";
	switch($char)
	{
		case "a" : echo "这是一个元音“a”\n"; break;
		case "e" : echo "这是一个元音“e”\n"; break;
		case "i" : echo "这是一个元音“i”\n"; break;
		case "o" : echo "这是一个元音“o”\n"; break;
		case "u" : echo "这是一个元音“u”\n"; break;
		default:
			echo "这是一个辅音“".$char."”\n";
	}*/
	/*$char = "a";
	switch($char)
	{
		case "a" : 
		case "e" : 
		case "i" : 
		case "o" : 
		case "u" : 
			echo "这是一个元音“".$char."”\n";
		break;
		default:
			echo "这是一个辅音“".$char."”\n";
	}*/

	/*$i = 0;
	while($i<=100)
	{
		echo $i;
		echo "\n";
		$i++;
	}*/
	/*$i = 0;
	while(++$i<100)
	{
		echo "$i\n";
	}*/
	/*$arr = array('apple','orange','pear');
	reset($arr);
	while(list($index,$fruit) = each($arr))
	{
		echo "第".$index."这种水果是:".$fruit."\n";
	}*/
	/*$i = 0;
	while($i<10):
		echo "*";
		$i++;
		endwhile;*/
	/*$i = 1;
	do{
		echo $i;
		echo"\n";
		$i++;
	}while($i<100);*/

	/*$lines = array(
		"两只黄鹂鸣翠柳,",
		"一行白鹭上青天。",
		"窗含西岭千秋雪,",
		"门泊东吴万里船。"
	);
	for($i=0;$i<count($lines);$i++)
	{
		if($i%2==0)
			$color="red";
		else
			$color="green";
		echo '<font color="'.$color.'">'.$lines[$i].'</font>';
		echo "<br/>\n";
	}*/

	/*$arr = array('apple','orange','pear');
	$i = 0;
	foreach($arr as $fruit)
	{
		echo "第".$i."种水果是:".$fruit."\n";
		$i++;
	}*/

	/*$arr = array('apple','orange','pear');
	foreach($arr as $index => $fruit)
		echo "第".$index."种水果是:".$fruit."\n";*/

	/*$i = 1;
	do{
		echo "$i\n";
		if($i++>=50)
		{
			break;
		}
	}while(1);
	echo "<hr/>";
	for($i=0; ;)
	{
		if($i++ >= 50) break;
		echo "$i\n";
	}*/

	/*$arr = array('one','tow','three','four','five','six');
	while(list ($index,$value) = each($arr))
	{
		if(!($index % 2))
		{
			continue;
		}
		echo $value."\n";
	}*/
	/*$i = 0;
	while($i++<4)
	{
		echo "外部<br/>\n";
		for(;;)
		{
			echo "&nbsp; for循环的内部<br/>\n";
			do{
				echo "&nbsp;do-while循环内部<br/>\n";
				continue 3;
			}while(1);
			echo "这行不会输出<br/>\n";
		}
		echo "从未运行到这<br/>\n";
	}*/
	/*function cal_circle_area($radius)
	{
		$area = M_PI * ($radius * $radius);
		return $area;
	}
	$the_radius = 5;
	$the_area = cal_circle_area($the_radius);
	echo "半径为{$the_radius}的圆的面积是{$the_area}。";*/

	/*echo cal_circle_area(5.0);
	function cal_circle_area()
	{
		return M_PI * ($radius * $radius);
	}*/

	/*
		如果file_get_contents不存在,则使用自定义的版本
		file_get_contents函数在PHP4.2.0中首次引入。
	*/
		/*if(!function_exists("file_get_contents"))
		{
			function file_get_contents($filename)
			{
				$handle = fopen($filename,"r");
				$contents = fread ($handle,filesize($filename));
				fclose($handle);
				return $contents;
			}
		}
		$string = file_get_contents("data.txt");*/

	/*$input_array = array(5,9);
	function take_sum($input)
	{
		echo "$input[0] * $input[1] = ",$input[0] * $input[1];
	}
	take_sum($input_array);*/

	/*function change_data(&$string)
	{
		$string .='We changed something.';
	}
	$str = 'This is original string.';
	change_data($str);
	echo $str;*/

	/*function hello_teens($name,$age=10,$sex="M")
	{
		echo "$name is a";
		if($sex == "M")
			echo "boy . he is";
		else
			echo "girl . she is";
		echo  "$age years old.\n";
	}
	hello_teens("Ailce",9,"F");
	hello_teens("Jack",8);
	hello_teens("Tom");*/

	/*function more_args()
	{
		$args = func_get_args();
		foreach($args as $current_arg)
		{
			echo $current_arg . PATH_SEPARATOR;
		}
	}
	more_args("A","B","C");*/

	/*function more_args()
	{
		$num = func_num_args();
		for($i=0;$i<$num;$i++)
		{
			echo $current_arg . PATH_SEPARATOR;
		}
	}*/

	/*$var = "Hello,PHP World!";
	function TestVar()
	{
		echo $var;
	}
	TestVar();
	echo $var;*/

	/*$var ="Hello World!";
	function TestVar()
	{
		global $val;
		echo $val;
	}
	TestVar();*/

	/*$var = "Hello World!";
	function TestVar()
	{
		echo $GLOBALS["var"];
	}
	TestVar();*/

	/*function StaticVar()
	{
		static $var = 0;
		$var = $var + 1;
		echo $var;
	}
	StaticVar();
	StaticVar();
	StaticVar();
	StaticVar();
	StaticVar();*/

	/*function Factorial($n)
	{
		if($n == 0)
			return 1;
		else
			return n * Factorial(n-1);
	}*/

	$arr[1] = 1;
	for($i = 2;$i < 100;$i++)
	{
	    $arr[$i] = $arr[$i-1] + $arr[$i-2];
	}
	echo join(",",$arr);//将数组合并为一个字符串输出

?>	
<?php
	//echo strlen("fhdjskfhkfdjslfjdkslf");
	
	//$string = "Nothing is impossible. Just do it!";

	//$just = substr($string,23,4);
	//$just = substr($string,-11,4);
	//$center = substr($string,11,11);
	//echo substr($string,-11);
	//echo substr($string,-1);
	//echo $just;
	//echo $center;

	/*$string = "wxyz wxyzdsafsdasdyyyyy";
	$first = strpos($string,"x");
	$last = strrpos($string,"x");

	$zero = strpos($string,"w");
	$pos = strrpos($string,"y",3);

	echo $first."\n".$last."\n".$zero."\n".$pos;*/

	/*$str = 'There is some letters.';
	$first = $str{0};
	$fourth = $str{3};
	$last = $str{strlen($str)-1};

	echo $first;
	echo $fourth;
	echo $last;*/

	/*$string = "ABCDEFGHIJKLMN   ABCDEFGHIJKLMN";
	for($i=strlen($string);$i>=0;$i--)
	{
		echo $string{$i};
	}*/
	//字符串中的分割和连接
	/*$this_year = 2016;
	$text = <<<EOT
111,F,1982,广东,普通职员
222,M,1981,河北,普通职员
333,F,1980,山西,项目经理
EOT;
	$lines = explode("\n",$text);
	foreach($lines as $userinfo)
	{
		$info = explode(",",$userinfo,5);
		$name = $info[0];
		$sex = ($info[1] == "F" ? "女" : "男");
		$age = $this_year - $info[2];
		$add = $info[3];
		$work = $info[4];

		echo "姓名:$name $sex 年龄:$age 所在地:$add 职位:$work<br/>";
	}*/

	//连接数组成为字符串
	/*$fruits = array('apple','banana','orange');
	$imploded_string = join(",",$fruits);
	echo $imploded_string;*/


?>
<?php
	/*if(isset($_POST['submit']))
	{
		if(!trim($_POST['title']))
		{
			echo "<p><font color=red>标题没有填写!</p>";
		}
		elseif(! trim($_POST['content']))
		{
			echo "<p><font color=red>正文没有填写!</font></p>";
		}else{
			echo $_POST['title'];
			echo "<hr/>";
			echo $_POST['content'];
		}
	}*/	

?>
<!-- <form method="post" action="">
	标题:<input type="text" name="title" value=""/>
	正文:<textarea name="content"></textarea>
	<input type="submit" name="submit" value="提交"/>
</form> -->
<?php
		/*$string = "   xxx There is something unwanted...";
	$left = ltrim($string);
	$right = rtrim($string,".");
	$full = trim($string,"x .");
	echo $left;
	echo $right;
	echo $full;*/

	//字符串的填补
	/*$prices = array(
		"人员工资" => 42840,"房租" => 4000,"维修费" => 925
	);
	$sum = 0;
	foreach($prices as $title => $pay)
	{
		$sum += $pay;
		echo str_pad($title,10," ");
		echo str_pad($pay,10,"*",STR_PAD_LEFT);
		echo "¥\n";
	}

	echo str_repeat("-",30),"\n";

	echo str_pad("总支出",10," ");
	echo str_pad($sum,10,"*",STR_PAD_LEFT);
	echo "¥\n";*/

	//字符串反转
	//echo strrev("Hello World");

	//字符串大小写的转换
	/*strtoupper();//将给定的字符串全部转换成大写字母
	strtolower();//将给定的字符串全部转换成小写字母
	ucfirst();//将给定的字符串首字母转换成大写
	ucwords();//讲给顶的字符串中全部单词的首字母传换成大写,以空白(空格,TAB等)分割*/

	/*$str = "Tom Is A PHP Programer.";
	$lower = strtolower($str);
	$upper = strtoupper($str);
	$string = 'hello PHP world!';
	echo ucfirst($string);
	echo "<hr/>";
	$php = "php:hypertext preprocessor";
	$php = ucwords($php);
	echo $php;
	echo "<hr/>";
	$word = "i try do some programming/repairing.";
	$word = ucwords($word);
	echo $word;*/

	/*$string = 'HELLO PHP WORLD!';
	echo ucfirst($string);
	echo ucfirst(strtolower($string));*/

	/*$test = strcmp("Thomas","Tom");
	if(strcmp("大连","大庆")>0)
	{
		echo "大连";
	}else{
		echo "大庆";
	}*/

	/*$str1 = "php gRoUp";
	$str2 = "PHP Group";
	$test = strcasecmp($str1,$str2);
	$test = strcmp(strtolower($str1),strtolower($str2));
	echo $test;*/

	/*$num = 123;
	$str = "abc";
	var_dump($num > $str);
	var_dump("$num" > $str);
	var_dump(strcmp($num,$str));*/

	/*$arr = array(
		"photo.jpg","photo2.jpg","photo10.jpg","photo12.jpg"
	);
	$max_str = $arr[0];
	for($i=1;$i<count($arr);$i++)
	{
		if(strnatcmp($arr[$i],$max_str)>0)
		{
			$max_str = $arr[$i];
		}
	}
	echo $max_str;*/

	/*echo soundex("rulley"),soundex("rooly")."\n";
	echo soundex("guest"),soundex("ghost")."\n";
	echo soundex("Heilbronn"),soundex("Hilbert")."\n";
	echo soundex("Lloyd"),soundex("Ladd")."\n";*/

	/*echo similar_text("Heilbronn","Hilbert")."\n";
	echo similar_text("guest","ghost",$similar)."\n";
	echo $similar . "%"."\n";*/

/*	$template = <<< TPL
<table border=1>
	<tr bgcolor="%bgcolor1%">
		<td>line 1</td>
	</tr>
	<tr bgcolor="%bgcolor2%">
		<td>line 2</td>
	</tr>
	<tr bgcolor="%bgcolor1%">
		<td>line 3</td>
	</tr>
	<tr bgcolor="%bgcolor2%">
		<td>line 4</td>
	</tr>
</table>
TPL;
	$template = str_replace("%bgcolor1%","#FFCCEE",$template);
	$template = str_replace("%bgcolor2%","$339966",$template);
	echo $template;*/

	/*$vowels = array("a","A","e","E","i","I","o","O","u","U");
	$string = "Replace All Vowels in String.";
	echo str_replace($vowels,"*",$string);*/

	/*$search = array(
		"<",
		">",
		"\"",
		"*"
	);
	$replace = array(
		"&lt;",
		"&gt;",
		"&quot;"

	);
	$string = '<a href="links.php">链*接*地*址</a>';
	echo str_replace($search,$replace,$string);*/

	/*$string = 'http://movie.welcome-to-China.com';
	echo strtr($string,'com','net');*/

	/*$string = 'http://movie.welcom-to-China.com';
	$change = array('com' => 'net','http' => 'https');
	echo strtr($string,$change);*/

	/*$date = sprintf("%04d-%02d-%02d",2006,9,3);
	$money1 = 1038.45;
	$money2 = 2154.75;
	$sum_money = sprintf("%01.2f¥",$money1 + $money2);
	$format = "There are %d dogs in the %s.";
	printf($format,"5.1","my room");
	printf("%.2f%%",32.1);
	$num = 1234;
	printf("The hex value of %d is %X",$num,$num);*/

	/*$number = 1234.56748;
	$internet_format = number_format($number);
	$internet_format = number_format($number,2);
	echo $internet_format;*/

	$number = 1234.5678;
	$european_format = number_format($number,2,',',' ');
	echo $european_format;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>HTML表单</title>
</head>
<body>
	<?php
		if(isset($_POST['submit']))
		{
			//提交后的处理
			echo "<p>标题:".$_POST['title']."</p>\n";
			echo "<p>正文:".$_POST['content']."</p>\n";
			echo "<a href=\"?\">返回</a>\n";
		}else{
	?>
	<form action="" method="post">
		标题:<input type="text" name="title" size=40/><br />
		正文:<textarea name="content" cols="40" rows="10"></textarea><br />
		<input type="submit" name="submit" value="提交"/>
	</form>
	<?php
		}
	?>
</body>
</html>
<?php
	/*$text = '<p>段落标记:<b>粗体</b>字</p>';
	echo strip_tags($text);
	echo "\n----\n";
	echo strip_tags($text,'<i><b>');*/

	/*$data = array(
		'foo' => 'bar',
		'baz' => 'boom',
		'cow' => 'milk',
		'php' => 'hypertext processor'
	);
	echo http_build_query($data);

	$data = array(
		'foo','bar','cow' => 'milk',
		'php' => 'hypertext processor'
	);
	echo http_build_query($data);
	echo http_build_query($data,'var_');*/
	//url字符串解析
	/*function build_query($formdata,$key = null)
	{
		$res = array();
		foreach((array)$formdata as $k=> $v)
		{
			$tmp_key = urlencode($k);
			if($key) $tmp_key = $key.'['.$tmp_key.']';
			if(is_array($v))
			{
				$res[] = build_query($v,$tmp_key);
			}else{
				$res[] = $tmp_key."=".urlencode($v);
			}
 		}
 		return implode("&",$res);
	}
	$query = array(
		"col" => array("blue","red"),
		"fav" => "books",
		"id" => array("u001",array(11,22))
	);
	echo build_query($query);*/
?>
<?php
	/*$array = array(
		"input" => "200V",
		"output" => "1.5V",
		"battery" => array("a" => "Cell")
	);
	print_r(array_keys ($array));
	echo "<hr/>";
	print_r(array_values ($array));*/

	/*$var_array = array(
		"apple",
		"PI" => "3.14",
		"num" => 1000,
		array('a','b')
	);
	if(in_array("apple",$var_array))
	{
		print "字符串\n";
	}
	if(in_array(3.14,$var_array,true))
	{
		print "圆周率\n";
	}
	if(in_array(array("b","a"),$var_array))
	{
		print "数组\n";
	}*/
	/*$var_array = array(
		"apple",
		"PI" => "3.14",
		"num" => 1000,
		array('a','b')
	);
	if(($key=array_search("apple",$var_array))===TRUE)
	{
		print "键名:".$key;
		print "元素:".$var_array[$key];
	}*/

	/*$fruits = array(
		"a" => "apple","b" => "banana","c" => "cherry","pear","orange","grape"
	);
	next($fruits);
	$foo = each($fruits);
	print_r($foo);
	echo "Current Value:" . current($fruits);*/

	/*$info = array(
		"user_id" => 2006001,
		"username" => "111",
		"position" => "项目经理"
	);
	var_dump(extract($info));*/

	/*$province = "广东";
	$array = array(
		"name" => "1234",
		"province" => "河北",
		"age" => 25
	);
	extract($array,EXTR_PREFIX_SAME,"user");
	print "$name,$province,$age,$user_province";*/

	/*$city = "大连";
	$province = "辽宁省";
	$project = "PHP Programm";
	$location_vars = array("province","city");

	$result = compact("project","nothing",$location_vars);
	print_r($result);*/

	$input = array("a" => "A","B","C","d"=>"D","E");
	$output = array_slice($input,2);
	echo $output;

?>

 

© 著作权归作者所有

上一篇: php正则练习
粉丝 0
博文 65
码字总数 21935
作品 0
南京
私信 提问
Python编程 的练手项目有哪些值得推荐?

不得不说 github 很有用 一、不同的阶段,不同的练习 我把IT编程类的学习,一般分为以下几个阶段: 程序逻辑阶段 练习基本都是解答数学题,如万年历,斐波那契数列,完全数,鸡兔同笼问题。要...

铁扇公主1
2017/03/24
429
0
项目设计方案概要

一、设计概述 1、系统模块 1.1、App 登录注册、密码修改、答题、科目、答疑、激活码、错题练习、订单、支付、收藏、评估、个人资料管理等模块。 1.2、接口 同App对应。 1.3、代理/分销 登陆、...

橙汁儿
2016/07/06
108
0
python基础语法

python编程基础概念: 程序: 一组能让计算机识别和执行的指令; 电子计算机:能够执行程序的机器; 冯诺依曼体系架构: CPU由运算器和控制器组成; 运算器:完成各种算术运算,逻辑运算,数...

羽丰1995
2017/09/16
0
0
求助,c#学习,或者说.net入门

[求助]本人有点php基础,现在需要切换到c#,看过语法之后,web开发还是很无力,怎么练习,快速上手,mvc看了,很多不明白(看过musicstore),求指导

sork
2014/05/18
255
6
java基础重点讲解,看了还不会找我(三)

###03.01_Java语言基础(逻辑运算符的基本用法)(掌握) * A:逻辑运算符有哪些 * &,|,^,! * &&,|| * B:案例演示 * 逻辑运算符的基本用法 * 注意事项: * a:逻辑运算符一般用于连接boolean类型的...

谢小芳是女神
2018/12/30
0
0

没有更多内容

加载失败,请刷新页面

加载更多

安卓Q | 文件存储沙箱化FAQ,你想知道的这里都有!

文件存储沙箱化作为Android Q最为重要的变更之一,对应用文件存储、访问、分享等操作都带来重大的影响,被众多开发者关注和讨论。本文邀请华为技术专家对开发者提到的重点问题进行了解答,以...

安卓绿色联盟
10分钟前
0
0
可以提高程序员效率的工具!

前言 只有光头才能变强。 文本已收录至我的GitHub仓库,欢迎Star:https://github.com/ZhongFuCheng3y/3y 本文记录一下我在平时喜欢用的一些小工具,以便以后重装系统/换电脑的时候能快速安装...

Java3y
32分钟前
3
0
将博客搬至CSDN

https://blog.csdn.net/qq_38157006

Marhal
38分钟前
1
0
unicode Java中求字符串长度length()和codePointCount()的区别

在计算字符串长度时,Java的两种方法length()和codePointCount()一度让我困惑,运行书上例子得到的长度值是相等的,那为什么要设定两个方法呢? 对于普通字符串,这两种方法得到的值是一样的...

泉天下
38分钟前
2
0
uin-app 一、学习理由

选择uni-app 理由 别人的理由 1. 5+ 有HTML5+和Native.js技术,HTML5+包含常用的跨平台的几百个API,能满足常规开发需求,而Native.js把40w原生api映 射成js对象,这样js可以直接调原生。HTM...

轻轻的往前走
40分钟前
1
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部