Why doesn't my PHP function work as expected?

Php programming: why this function doesnt work?

  • <?php $d1="hello"; $t4="yes"; $t5="ok"; function abc($a,$b,$c) { if ($b="") { $c=$a; } else { $c=$b; } } abc($d1,$t3,$o1); abc($d2,$t4,$o2); abc($d3,$t5,$o3); echo $o1; echo $o2; echo $o3; ?>

  • Answer:

    function doesn't return values........make the variebles global

Author at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

If you are trying to compare $b to an empty string, then you need to make that if($b == "") At the moment you are setting $b to an empty string. I hope this isn't homework!

diversenz

poojitra is right. what you send to the function are copies of your parameters, and what you change inside the function are not originals, but copies. you can do this: function abc($a, $b) { if ($b == "") $c=$a; else $c=$b; return $c; } $o2 = abc($d2, $t5); $o3 = abc($d3, $t5); better than making variables global IMHO

Bruno

COZ THERE ARE ONLY TWO QUESTION THERE & THE OTHER ONE IS BETTER

Sarang

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.