0

I have code below, where i need to get the return value in a variable outside a class and also its print with respective code.

http://codepad.org/mAlhYBll

and below is raw code.

<?php
    class test {
        public function kk() {
            echo "Whats up :";
            return "Hello";
        }
    }

    $obj = new test();
    $obj->kk();

    $abc = $obj->kk();
?>

Now how can i get value returned from a function added an image below

enter image description here

2 Answers 2

1

You need to echo $abc. The program is printing something else since you're echoing What's up within the method, remove that.

Sign up to request clarification or add additional context in comments.

4 Comments

Correct, though don't delete the echo, just print $abc as that is your problem.
@Andy yes, rather I shouldn't have asked to delete the other echo statement :-D
see guys: i have updated the code, but i dont want to remove that echo statement from function.. is there any possiblities. codepad.org/M2R8xzH8
@Rafee you don't need to remove the echo, but you should be echoing $abc which receives the return value from the method.
1

Exactly as you've done - although you call "kk()" twice, which is not nneeded, so drop line 13.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.