Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.