Jump to content

[SOLVED] loop


johnwayne77

Recommended Posts

i have a list of fieldA and fieldB as following:

 

"fieldA1","fieldB1"

"fieldA2","fieldB2"

"fieldA3","fieldB3"

 

stored in fields.txt

 

now i need to put fieldA and fieldB in its own variables as following:

 

$fielda = "fieldA1";

$fieldb = "fieldB1";

 

then run a function as following:

 

$function = function($fielda,$fieldb);

 

then run an echo as following:

 

echo $function;

 

how do i extract all fieldA and fieldB fields from fields.txt, apply the function to obtain the echo and create a loop to do that for all existent fieldA and fieldB

 

any ideas, logical algorithm or advices much appreciated.

 

thanks.

Link to comment
https://forums.phpfreaks.com/topic/135555-solved-loop/
Share on other sites

is the file a CSV file?

 

replace functionName with the name of your function...

<?php
  $filename='fields.txt';
  $handle = fopen($filename,'r');
  while (($data = fgetcsv($handle)) !== FALSE)
  {
    echo functionName($data[0],$data[1]);
  }
  @fclose($handle);
?>

Link to comment
https://forums.phpfreaks.com/topic/135555-solved-loop/#findComment-706159
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.