1.改变多维数组的键值
/**用法: $keyEnArray = array("奖品" , "标识","编码"); $keyZhCnArray = array(‘prize‘, ‘sign‘,‘code‘); $result = changeKeys($data, $keyEnArray, $keyZhCnArray);
$keyEnArray 原键值
$keyZhCnArray 改变后的键值
*/ function changeKeys($array, $keyEnArray, $keyZhCnArray) { if(!is_array($array)) return $array; $tempArray = array(); foreach ($array as $key => $value){ // 处理数组的键,翻译成中文 $key = array_search($key, $keyEnArray, true) === false ? $key : $keyZhCnArray[array_search($key, $keyEnArray)]; if(is_array($value)){ $value = changeKeys($value, $keyEnArray, $keyZhCnArray); } $tempArray[$key] = $value; } return $tempArray; }
2.循环三维数组,插入数据库
foreach($result as $value){ foreach($value as $key=> $v){ $arr2[$key]=$v; } pdo_insert(‘hxqlottery_prize‘,$arr2); }
原文地址:https://www.cnblogs.com/tine/p/9176114.html
时间: 2024-11-09 15:10:51