Home > Backend Development > PHP Tutorial > PHP Array 学习记要(1)

PHP Array 学习记要(1)

WBOY
Release: 2016-06-13 13:04:23
Original
1085 people have browsed it

PHP Array 学习记录(1)
关于数组的一些方法

$test_arr = array(
			'name' => 'test',
			2 => 2,
			'color' => "red"
		);
		echo '使用var_dump方法输出数组:';
			var_dump($test_arr);
		echo '<br><br>使用print_r方法输出数组:';
			print_r($test_arr);
		if(is_array($test_arr)){
			echo "<br><br>$ test_arr是一个数组";
		}

		echo "<br><br> array_push在数组添加项目";
		array_push($test_arr,array('good','nice'),'three','four');
		var_dump($test_arr);

		echo "<br><br> array_pop用法";
		array_pop($test_arr);
		print_r($test_arr);

		echo "<br><br> array_shift返回数组中的第一个元素";
		$b = array_shift($test_arr);
		print_r($b);

		echo "<br><br> array_unshift:";
		array_unshift($test_arr, 'unshift');
		print_r($test_arr);
		
		echo "<br><br> array_pad:";
		$c = array_pad($test_arr, -7 , 'xiang');
		print_r($c);
		
		echo "<br><br> in_array:";
		if(in_array(2, $test_arr)){
			echo 'in_array through validate';
		}else{
			echo 'validate die.';	
		}

		echo "<br><br> array_keys:返回数组键名组合成一个集合:";
		$allmarke = array_keys($test_arr);
		var_dump($allmarke);
Copy after login

待完善
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template