<?php
/**
 * 数组(二)each() list() implode() explode() in_array()
 */

/*implode() 把数组拆分成字符串
 * explode()把字符串分割成数组
 *
 * */
/*$arr=array('PHP课程','DIV+CSS课程','JQUERY','JAVASCRIPT');
$str=implode(',',$arr);//输出:PHP课程,DIV+CSS课程,JQUERY,JAVASCRIPT
echo $str;*/

/*$file=array('/uploads/a1.jpg','/uploads/a2.jpg','/uploads/a3.jpg','/uploads/a4.jpg',);
$files=implode(',',$file);
echo $files."<br/>"; //输出:/uploads/a1.jpg,/uploads/a2.jpg,/uploads/a3.jpg,/uploads/a4.jpg
$arr2=explode(',',$files);
print_r($arr2);//输出:Array ( [0] => /uploads/a1.jpg [1] => /uploads/a2.jpg [2] => /uploads/a3.jpg [3] => /uploads/a4.jpg )*/


/*
 *in_array()检测内容是否在数组中
 * */
/*$arr3=array(1,2,3,4,5);
var_dump(in_array(4,$arr3,TRUE));//输出: true 。第三个参数,要求对比的参数类型也要相等。相当于====*/

/*
 *each()把数组元素拆分成新的数组:
 * */
/*$arr4=array('url'=>"bbs.blog.com",'webname'=>'博客项目');
$arr4_1= each($arr4);
print_r($arr4_1); //输出:Array ( [1] => bbs.blog.com [value] => bbs.blog.com [0] => url [key] => url )
$arr4_1= each($arr4);
print_r($arr4_1);//输出:Array ( [1] => 博客项目 [value] => 博客项目 [0] => webname [key] => webname )*/

/*list()把数组元素赋值给变量:只对索引型数组有作用。
 *
 * */
/*$arr5=array('bbs.blog.com','博客视频教程');
list($url,$webname)=$arr5;
echo $url;//输出:bbs.blog.com
echo "<br/>";
echo $webname;//输出:博客视频教程*/
/*$arr5=array('url'=>'bbs.blog.com','webname'=>'博客视频教程');
list($k,$v)=each($arr5);
echo $k,$v;//输出:bbs.blog.com 博客视频教程*/

$arr5=array('url'=>'bbs.blog.com','webname'=>'博客视频教程'); while (list($k,$v)=each($arr5)){ echo $k."=>".$v; echo "<br/>"; } //输出:url=>bbs.blog.com //输出:webname=>博客视频教程