Jump to content

Array Question


ballouta

Recommended Posts

Hi, I have this piece of code to pull up data from a text file, and it is working properly,

Each line is actually an email address, I want to send a message for this email address.

my Question is:

 

A.Why we are printing $fields[0] $fields[2] and NOT $fields[$k]? although the out put is correct.

B. And if i am using the mail fuction does this seem correct:

 

mail('$fields[0] $fields[2]', $subject, $message, $headers);

 

<?php
$readfile = file("files/$output");
for ($k=0; $k<=count($readfile)-1; $k++) {
    $fields = split("\t",$readfile[$k]);
    print("$fields[0] $fields[2]<br>"); // this is working too	
?>

 

Thank you

Link to comment
https://forums.phpfreaks.com/topic/138539-array-question/
Share on other sites

Why we are printing $fields[0] $fields[2] and NOT $fields[$k]? although the out put is correct.

$k is incrementing through the array. You're splitting each line into fields and only need the 1st & 3rd field.

And if i am using the mail fuction does this seem correct:

<?php
   mail('$fields[0] $fields[2]', $subject, $message, $headers);
?>

Without knowing what the data in your file looks like, we can't answer this question.

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/138539-array-question/#findComment-724348
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.