I'm having some problems trying to use a return on values stored in an array once they have passed through an str_replace function.
When the code is working properly, I have a print statement on another page that should reference the class containing this function, perform the necessary things, and display the following: John Smith $9.95.
I was able to make this work by using a print_r() statement in the function, but when I changed it to a return() statement, it no longer works properly. Both codes are shown below...
The non-working code with the return() statement. This "prints" John:
function getText()
{
foreach ($this->FieldArray as $this->field)
{
// Find the FieldList name and replace with value ex: Replace First-Name with John
str_replace($this->name, $this->value, $this->field);
// Return the results of the str_replace
return ($this->params{$this->field} . ' ');
}
}
The following code WAS working properly, and displays John Smith $9.95, which is the correct output using the print_r() statement:
function getText()
{
foreach ($this->FieldArray as $this->field)
{
// Find the FieldList name and replace with value ex: Replace First-Name with John
str_replace($this->name, $this->value, $this->field);
// Print the results of the str_replace
print_r($this->params{$this->field} . ' ');
}
}
What can I do to get this to work properly with the return() statement and NOT the print_r() statement?
Thanks for any help!