FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


add to an array





Dark-Tech
So i have this code as follows

So i have this code as follows

Code:
$new_files_info = (!empty($xml_actions['COPY'])) ? $xml_actions['COPY'] : array();
      for ($i = 0; $i < sizeof($new_files_info); $i++)
      {
         $new_files = $new_files_info[$i]['children']['FILE'];
         for ($j = 0; $j < sizeof($new_files); $j++)
         {
            $from = str_replace('\\', '/', $new_files[$j]['attrs']['FROM']);
            $to = str_replace('\\', '/', $new_files[$j]['attrs']['TO']);
                     $actions['NEW_FILES'][$from] = $to;
         }
      }


And i modified it to do multiple overwrites instead of one.
However each destination overwrites the first instead of adding to the array
can someone help me... this is the way the code currently looks


Code:
$new_files_info = (!empty($xml_actions['COPY'])) ? $xml_actions['COPY'] : array();
      for ($i = 0; $i < sizeof($new_files_info); $i++)
      {
         $new_files = $new_files_info[$i]['children']['FILE'];
         for ($j = 0; $j < sizeof($new_files); $j++)
         {
            $from = str_replace('\\', '/', $new_files[$j]['attrs']['FROM']);
            $to = str_replace('\\', '/', $new_files[$j]['attrs']['TO']);
            //mod for prosilver replace
            if(strpos($to, 'prosilver') ? true : false)
               {
                  $fixedpath = str_replace('prosilver', '*', $to);
                  $staroccur = strpos($fixedpath, '*');
                  $frontpath = substr($fixedpath , 0, $staroccur);
                  $backpath = strstr($fixedpath, '*');
                  $backoccur = strpos($backpath, '/', 2);
                  $backpathb = substr($backpath , $backoccur);
                  $backsub = substr($backpath , 2, ($backoccur-2));
                  $pathread = $frontpath . "*/" . $backsub;
                     $paths = glob($_SERVER['DOCUMENT_ROOT'] ."/anime/". $pathread);
                  for ($q = 0; $q < sizeof($paths); $q++)
                  {
                  $returnpath = str_replace($_SERVER['DOCUMENT_ROOT'] ."/anime/", '', $paths[$q]);
                  $actions['NEW_FILES'][$from] = $returnpath . $backpathb;
                  }
               }
               else
               {
               $actions['NEW_FILES'][$from] = $to;
               }
         
         }
      }
Aredon
I haven't had a chance to look at your code too extensively yet, but have you tried using an array_push method instead?
halilibo
if the NEW_FILES and/or $from part is the same in all records, that would overwrite. if different than adds a new record.

if you want it to adds new records in all cases you should you it like:

Code:
$actions['NEW_FILES'][$from][]=$to


then you can see it under
Code:
$actions['NEW_FILES'][$from][0]
$actions['NEW_FILES'][$from][1]
openup
try array_push and u better give a new var name for $new_files : array();
sonam
I think the halilibo solution is the better and simpler then array_push especially in for and foreach loops.

Sonam
Related topics
why not add quick reply
add some media code in the forum
[java scripts ] Multimedia
help add admin in phpbb forum
Why don't add Chinese in'Other Languages' board
[java scripts] Text effect , img ....
SnowScript
Text stecked to the mouse
php sessions
AwStats "Add to Favorites" reliability
Better AD "showing"
Actionscript Problem: array failure?
array question
PHP "add" function [fixed]
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.