0

what is wrong with the following code? Hope you understand what I'm trying to do. I'm not very familiar with functions.

function test ($variable) {
   $one = 3;
   if ($variable == 10) {
       $one = "2";
   }
   return $one;
}

foreach ($array as $arraypart) { 
   $part = explode(',',$arraypart);
   test($part[0]);
   echo $one;
}
3

2 Answers 2

5

You need to assign the result of function to a variable:

$one = test($part[0]);
Sign up to request clarification or add additional context in comments.

2 Comments

You should also point out that this $one is different than the $one in the test function.
Or just directly echo it... echo test($part[0]);
0

here what happens, your function is being called but no variable is there to catch what test() is returning....

you need catch value which is returned by temp func like this

$val = temp($part[0]); or you can write direct echo temp($part[0]);

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.