Welcome Guest, Not a member yet? Register   Sign In
[Solved] Return $data question
#1

(This post was last modified: 02-15-2016, 03:37 AM by wolfgang1983.)

When I var dump my my $message variable it displays the multiple messages which is  correct.

But the return only shows one as shown here.

[Image: error_s.png]

How can I produce the same on return


PHP Code:
public function display_error_messages($open_tag '<p>'$close_tag '</p>') {

if (isset(
$this->error_message)) {

 
 foreach($this->error_message as $msg) {

 
   $message $open_tag $msg $close_tag;
 
   var_dump($message);

 
 }


}

return 
$message;


There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

You recreate (and overwrite) the $message variable instead of appending the second and third messages to it. Try:
PHP Code:
$message .= $open_tag $msg $close_tag
Reply
#3

(02-15-2016, 02:51 AM)Diederik Wrote: You recreate (and overwrite) the $message variable instead of appending the second and third messages to it. Try:
PHP Code:
$message .= $open_tag $msg $close_tag

I did this now but no getting undefined variable $message

PHP Code:
public function display_error_messages($open_tag '<p>'$close_tag '</p>') {

 
       if (isset($this->error_message)) {
 
           foreach($this->error_message as $msg) {
 
              $message .= $open_tag $msg $close_tag;
 
              var_dump($message);
 
           }


 
       }

 
       return $message;

 
   
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#4

Define $message='' before entering the foreach loop.
Reply
#5

(02-15-2016, 03:02 AM)Avenirer Wrote: Define $message='' before entering the foreach loop.

Is This Correct

PHP Code:
public function display_error_messages($open_tag '<p>'$close_tag '</p>') {

 
       if (isset($this->error_message)) {

 
           $message "";

 
           foreach($this->error_message as $msg) {
 
               $message .= $open_tag $msg $close_tag;
 
           }


 
       }

 
       return $message;

 
   
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#6

(This post was last modified: 02-15-2016, 03:27 AM by Avenirer.)

if you defined the $message depending on the if statement, then you should also return the $message from inside the if statement...

Code:
public function display_error_messages($open_tag = '<p>', $close_tag = '</p>') {

        if (isset($this->error_message)) {

            $message = "";

            foreach($this->error_message as $msg) {
                $message .= $open_tag . $msg . $close_tag;
            }
            return $message;


        }
        return FALSE; // or whatever you want to return in case there are no error messages...

        

    } 
But it is you who should tell me if it's correct or not Smile
Reply
#7

(02-15-2016, 03:27 AM)Avenirer Wrote: if you defined the $message depending on the if statement, then you should also return the $message from inside the if statement...

Code:
public function display_error_messages($open_tag = '<p>', $close_tag = '</p>') {

        if (isset($this->error_message)) {

            $message = "";

            foreach($this->error_message as $msg) {
                $message .= $open_tag . $msg . $close_tag;
            }
           return $message;


        }
       return FALSE; // or whatever you want to return in case there are no error messages...

        

    } 
But it is you who should tell me if it's correct or not Smile


Thank you for help it all works now. And thank you to every body else to.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB