4
如果我的問題很蠢,請原諒我。但請有人告訴我或建議我如何解決這個問題。實際上我有大多維數組如何在處理大型數組時增加php的執行速度?
這樣
$array_value = Array
(
[0] => Array
(
[0] => sdfsf
[1] => fghbfh
[2] => sgddfsg
[3] => ujmnm
[4] => jkluik
..
..
..
..
..
..
[150] => jhbjhbjh
)
[1] => Array
(
[0] => 44062
[1] => 45503
[2] => 44062
[3] => fdg
[4] => dfgdg
..
..
..
..
..
..
[150] => jhbjhbjh
)
....
....
....
[590] => Array
(
[0] => 44062
[1] => 45503
[2] => 44062
[3] => fdg
[4] => dfgdg
..
..
..
..
..
..
[150] => jhbjhbjh
)
)
600 600陣列的內部陣列我有150個數組值。當我使用這個數組,如果foreach條件和循環條件需要超過5分鐘才能完成執行。
我使用兩個foreach循環和一個for循環和四個循環內部方法函數。它需要超過5分鐘才能執行。我需要加載更快。
我不知道如何增加腳本的執行時間或如何處理這個數組。請有人建議或幫助我如何處理這個問題。謝謝。
foreach ($Final_Data as $line_no => $val) {
foreach($val as $col_name=> $col_value) {
if ($col_name === 'tid' || $col_name === 'pid' || $col_name === 'local_list_id')
{
if(empty($col_value)) {
$null_error[] = "empty value in ".$col_name;
}elseif($col_value !== null && !is_numeric($col_value)) {
$where_Error[] ="non numeric value in ".$col_name." = ".$col_value;
}
$where_content[]= $col_name . "= '" . $col_value."'";
if($col_name =='pid'){
$pid = $col_value;
}
}elseif(!empty($col_name) && in_array($col_name, $update))
{
if($col_name=="country"){
...
}elseif($col_name=="state"){
...
}elseif($col_name=="district"){
....
}elseif($col_name=="post_category")
{
....
$CategoryList=array();
if(count($locationArr) > 0 && count(locationCategory($locationArr)) > 0)
{
.....
}
if(strlen($col_value)==0 || empty($col_value))
{
......
}elseif(ValidateLength($col_name,$columnValue,$maxl) === false || VulnerableExists($columnValue)===false)
{
if(ValidateLength($col_name, $columnValue,$maxl) === false){
....
}
if(VulnerableExists($columnValue)===false){
....
}
}else
{
......
foreach($post_cat as $Category){
if(get_cat_ID($Category) == 0) {
if(!in_array($Category, $CategoryList)){
.....
}
}
}
/*****Category Mapping Start****/
if(count($post_cat)>0 && isset($pid) && !empty($pid) && count($CategoryList)==0)
{
$postCat = array();
$ex_catid = array();
$post_categories = get_the_category($pid);
foreach($post_categories as $category) {
if(in_array($category->name, $post_cat)){
.....
}
}
$array_dif = array_diff($post_cat,$postCat);
foreach($array_dif as $pc){
......
if($cat_Id!=0) array_push($ex_catid,$cat_Id);
}
if(count($array_dif)!=0){
......
}
}elseif(count($CategoryList)>0)
{
}
}
}
$columnName=$col_name;
$columnValue=mysqli_real_escape_string($link, $col_value);
if(ValidateLength($col_name,$col_value,$maxl)===false)
{
......
}elseif(VulnerableExists($col_value)===false)
{
......
}else
{
......
}
}
}
die();
// echo implode(", " ,$where_content)."<br>";
// echo implode(", " ,$update_content);
if(!empty($val['pid']) && !empty($val['tid']) && !empty($val['local_list_id'])) {
if(count($vuln_error) <= 0 && count($length_error)<=0 && count($null_error)<=0 && count($CategoryList)<=0){
....
}else
{
....
}
}
//die();
unset($where_content);
unset($update_content);
unset($null_error);
unset($vuln_error);
unset($length_error);
unset($CategoryList);
echo "<br><br>";
}
我給出了我的代碼的基本結構。這就是我的整個腳本在環境和foreach條件下會有多少條件。但所有條件都是強制性的,因爲它用於驗證和操作。請有人幫我解決這個問題。 Thankyou
這個數組中最重要的東西和問題是值是1000個字符和超過1000個字符。這裏我給出了4位數字和5個字符串。
你知道每個小陣列中'列'的總數嗎?數組鍵總是簡單的索引號嗎? – besciualex
validation_funtion作業是什麼?而你在哪裏使用$ value – hurricane
這個小數組創建動態依賴於excel文件。如果文件有150列,那麼密鑰將是150或將低於150.最大值是150 @besciualex – Munna