Looping array from csv file causing Fatal error: Maximum execution time of 30 seconds exceeded

I am trying to loop through the array from a csv file to insert new information. However, once the program hits the loop, it throws a time exception. I’m totally lost on this one… Any help would be greatly appreciated. Thank you in advance.

function readAndWriteToCsv(String $fullDirectory, Array $images, String $pageTitle)
{
//echo ‘<br>’;

$newDirectoryPath = $fullDirectory . ‘CSVproducts.csv’;
$lines2 = file($newDirectoryPath);
echo ‘Directory string made: ‘ . $newDirectoryPath;
echo ‘<br>’;

//$lines = file(‘D:Dropbox (Personal)white-performancescrap1-PAIR-OF-BBC-HEAD-GASKET-GASKETS-MULTI-LAYERED-STEEL-4.585pageTitle.txt’);

$csvTests = array_map(‘str_getcsv’, $lines2);

var_dump($csvTests);
echo ‘<br>’;
echo ‘<h2>’.$csvTests[1][3].'</h2>’;
echo ‘<br>’;
echo ‘<h2>’. sizeof($csvTests).'</h2>’;
echo ‘<br>’;
echo ‘<h2>’.$csvTests[1][28].'</h2>’;
echo ‘<br>’;
echo ‘<h2>’.$csvTests[2][3].'</h2>’;
echo ‘<br>’;
echo ‘<h2>’.$csvTests[2][28].'</h2>’;
echo ‘<br>’;
echo ‘<h2>’.$csvTests[3][3].'</h2>’;
echo ‘<br>’;
echo ‘<h2>’.$csvTests[3][28].'</h2>’;
echo ‘<br>’;

$arraySize = sizeof($csvTests);
echo $arraySize;

for($i = 0; i < $arraySize; $i++)
{
$productName = $csvTests[i][3];

if($productName == $pageTitle)
{
//array_fill_keys(‘images’, ‘TESTING YOUR MOMA’);
$csvTests[i][3][28] = implode(“, “, $images);
//array_push($csvTests[1][28], $image);
echo ‘<br>’;
echo ‘Images put in key value: ‘;
echo $csvTests[i][28];
echo ‘<br>’;
}

}

}

Read more here:: Looping array from csv file causing Fatal error: Maximum execution time of 30 seconds exceeded

Leave a Reply

Your email address will not be published. Required fields are marked *