stevenpepe
stevenpepe

Reputation: 267

Printing array info

I have a method that takes 3 arrays as arguments, then creates an array based on values from the 3 arrays passed through. This info is then sent to an email method that sends it off. It has worked fine until now. The problem is my key-value pairing. Some of the values are not printing and I'm not sure why. I have omitted unrelated code for illustration purposes. Take a look...

public function SendToISS($user,$questions,$scores_translated) {    

    $userinfo = array("First Name:"=>$user['first'],
                      "Last Name:"=>$user['last'],
                    "Organization:"=>$user['org'],
                      "State:"=>$user['state'],
                      "Zip:"=>$user['zip'],
                    "Phone:"=>$user['phone'],
                    "Email:"=>$user['email'],
                    ""=>"",

                    "Assessment Answers:"=>"",

                    "Assessment One:"=>$questions[0],
                    "  ".$user['first']."'s Answer:"=>$scores_translated[0],

                    "Assessment Two:"=>$questions[1],
                    "  ".$user['first']."'s Answer:"=>$scores_translated[1],

                    "Assessment Three:"=>$questions[2],
                    "  ".$user['first']."'s Answer:"=>$scores_translated[2],

                    "Assessment Four:"=>$questions[3],
                    "  ".$user['first']."'s Answer:"=>$scores_translated[3],

                    "Assessment Five:"=>$questions[4],
                    "  ".$user['first']."'s Answer:"=>$scores_translated[4]
                    );

}

This is the result in my email box. The scores_translated array is only printing the first value, then stopping.

 First Name: Steven
 Last Name: Pepe
 Organization: Laerdal
 State: New York
 Zip: 12590
 Phone: 8452977770
 Email: [email protected]

 Assessment Answers: 
 Assessment One: Administer multiple assessments of student progress throughout the class.
  Steven's Answer: The program does not perform this strategy.
 Assessment Two: Establish a passing standard for psychomotor and critical thinking skills that is above the minimum competency level.
 Assessment Three: The program does not perform this strategy.
 Assessment Four: Assure instructional consistency when preparing students for the NREMT-B exam.
 Assessment Five: Provide immediate feedback for written, practical evaluations to students.

Upvotes: 1

Views: 63

Answers (2)

zebediah49
zebediah49

Reputation: 7611

You appear to be using identical keys for the same thing. That is, you use "  ".$user['first']."'s Answer:" as a key for five different things, and are just overwriting rather than appending. I'm not sure why this used to work in the first place.

Try switching to something like "  ".$user['first']."'s Answer #1:", and numbering them, to see if that fixes it.

Upvotes: 1

elitechief21
elitechief21

Reputation: 3034

Your key's are not unique. This is the key that you are using in your array and it can only be set once "  ".$user['first']."'s Answer:"

You need something like "  ".$user['first']."'s Answer One:" for the keys to the responses

Upvotes: 1

Related Questions