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); }