idaachi Posted December 7, 2007 Share Posted December 7, 2007 I have an array containing a list of server names called $arPageServers I have another array containing variables and keys passed using a form which also reflect server names, this one is called $arActive. These elements in this array have been set by user to active. I.e the checkboxes are clicked in the form. First of all I want to set all the elements in $arPageServers to $arPageServers["active"]= false; then, for each $Aractive as $key => $value, I want to go through the $arPageServers from the beginning to the end and search if the values in $value["name"] gives a match. If match is true, I want to set the corresponding element in $arPageServers to $arPageServers["active"]= true; When this is done I want to write the new file to reflect these changes. This script just doesn't seen to work. Please help pinpointing a better way. Thanks. <?php $arActive = array(); if (array_key_exists("submit", $_GET)) { if (!empty($_GET["active"])) { $arActive = $_GET["active"]; }// end of(!empty($_GET["active"])) else { die(" I died here"); }//end of else }//end of array_key_exists("submit", $_GET)) foreach ($arActive as $key => $value) { $arActive[$key] = preg_replace("/^active_/", "", $value); } // Load page.conf $arPageConf = read_contents_pageconf("page.conf"); $arPageServers = create_servernamelist_pageconf($arPageConf); foreach($arActive as $key => $value) { $i=0; $MaxPageServers = count($arPageServers); for ($i=0; $i<$MaxPageServers; $i++) { $arCurrentPageServer = $arPageServers[$i]; } if( $arCurrentPageServer["name"] = $value) { $arPageServer[$key]["active"]= true; } //write new page.conf $nFileHandle = fopen("page.conf", "w"); $i=0; $nMaxlength = count($arPageServers); for ($i=0; $i<$nMaxlength; $i++) { $arCurrentLine = $arPageServers[$i]; $strNewLine =""; $bIsActive = $arCurrentLine["active"]; if ($bIsActive==false) { $strNewLine = $strNewLine."#"; }//end if ($bIsActive==false) //add URL to string $strNewLine = $strNewLine.$arCurrentLine["active"]."\t"; fwrite($nFileHandle,$strNewLine); }//end for ($i=0; $i<$nMaxlength; $i++) fclose($nFileHandle); Quote Link to comment Share on other sites More sharing options...
idaachi Posted December 7, 2007 Author Share Posted December 7, 2007 I had forgotten to setting all elements in $arPageServers["active"]=false; Still doesn't work. Help please. <?php $arActive = array(); if (array_key_exists("submit", $_GET)) { if (!empty($_GET["active"])) { $arActive = $_GET["active"]; }// end of(!empty($_GET["active"])) else { die(" I died here"); }//end of else }//end of array_key_exists("submit", $_GET)) foreach ($arActive as $key => $value) { $arActive[$key] = preg_replace("/^active_/", "", $value); } // Load page.conf $arPageConf = read_contents_pageconf("page.conf"); $arPageServers = create_servernamelist_pageconf($arPageConf); foreach($arPingServers as $key => $value) { if ($value["active"]= true) { $arPingServers[$key]["active"] = false; } } foreach($arActive as $key => $value) { $i=0; $MaxPageServers = count($arPageServers); for ($i=0; $i<$MaxPageServers; $i++) { $arCurrentPageServer = $arPageServers[$i]; } if( $arCurrentPageServer["name"] = $value) { $arPageServer[$key]["active"]= true; } //write new page.conf $nFileHandle = fopen("page.conf", "w"); $i=0; $nMaxlength = count($arPageServers); for ($i=0; $i<$nMaxlength; $i++) { $arCurrentLine = $arPageServers[$i]; $strNewLine =""; $bIsActive = $arCurrentLine["active"]; if ($bIsActive==false) { $strNewLine = $strNewLine."#"; }//end if ($bIsActive==false) //add URL to string $strNewLine = $strNewLine.$arCurrentLine["active"]."\t"; fwrite($nFileHandle,$strNewLine); }//end for ($i=0; $i<$nMaxlength; $i++) fclose($nFileHandle); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.