Jump to content

Accumulate Arrays


jkkenzie

Recommended Posts

Hi!

From The code below, check the $array variable, i want it to accumulate arrays if the !empty conditon is fullfilled.

 

What i want here is how do i accumulate the array?. This cant be the right way. Its not working.

$array=array();

if(!empty($_FILES['FrontPic']) && !empty($_FILES['FrontPic']['name'])){
   if(!empty($old_data) && !empty($old_data['FrontPic']) && file_exists($dir.$old_data['FrontPic'])) unlink($dir.$old_data['FrontPic']);
   $array ="'FrontPic'=>'FrontPic'";
  }
  
  if(!empty($_FILES['SidePic']) && !empty($_FILES['SidePic']['name'])){
   if(file_exists($dir.$old_data['SidePic']) && !empty($old_data) && !empty($old_data['SidePic'])) unlink($dir.$old_data['SidePic']);
   $array=."'SidePic'=>'SidePic'";
  }

  if(!empty($_FILES['RearPic']) && !empty($_FILES['RearPic']['name'])){
   if(!empty($old_data) && !empty($old_data['RearPic']) && file_exists($dir.$old_data['RearPic'])) unlink($dir.$old_data['RearPic']);
   $array=.array('RearPic'=>'RearPic');
  }
  
  if(!empty($_FILES['Pic4']) && !empty($_FILES['Pic4']['name'])){
   if(!empty($old_data) && !empty($old_data['Pic4']) && file_exists($dir.$old_data['Pic4'])) unlink($dir.$old_data['Pic4']);
   $array=.array('Pic4'=>'Pic4');
  }

Link to comment
https://forums.phpfreaks.com/topic/186575-accumulate-arrays/
Share on other sites

to add a value to an array you can use $array[] or $array['key']

 

For example.

if(!empty($old_data) && !empty($old_data['FrontPic']) && file_exists($dir.$old_data['FrontPic'])) unlink($dir.$old_data['FrontPic']);
   $array['FrontPic'] = 'FrontPic';
  }

 

Link to comment
https://forums.phpfreaks.com/topic/186575-accumulate-arrays/#findComment-985326
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.