时间:2021-07-01 10:21:17 帮助过:3人阅读
function array_2to1($array)
{
static $result_array=array();
foreach($array as $value)
{
if(is_array($value))
{
arrau_2to1($value);
}
else
$result_array[]=$value;
}
return $result_array;
}
//上面这段代码还可以简写
function _rebuild_array($arr){ //rebuild a array
static $tmp=array();
for($i=0; $i
else $tmp[]=$arr[$i];
}
return $tmp;
}
$arr = array_2to1( $array );
foreach( $arr as $v )
{
echo $v;
}
//现在再来看一个反一维数据保存到二维数据的实例
$arr_new=array();
$insert_key =array('uid','hostname','shopname','province','city','county','address','www.bkjia.com','qq','Mobile','msn');
$insert_value=array('2','hostname','shopname','province','city','www.bkjia.com','address','shopimg','qq','Mobile','msn');
//一在我们把2个数组一一对应写到一个新的二维数组里去
foreach($insert_key as $key => $val){
$arr_new[$val]=$insert_value[$key];
}
print_r($arr_new);
http://www.bkjia.com/PHPjc/444948.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444948.htmlTechArticlephp教程 把二维数组保存到一维数组教程 $array = array( array(1,2), array(3,4), array('www.bkjia.com','php100.com') ); //看到上面二维数结构了吧,下面我们...