EllisLab text mark
Advanced Search
     
return in PHP
Posted: 16 April 2012 03:19 AM
Joined: 2012-04-08
15 posts

I am new to codeigniter and PHP. I have a doubt in PHP. My code is something like this.

public function Test()
    
{
        $qryResult 
$this->GenerateRnd();
        
        if(
$qryResult == 1)
        
{
            
echo "True";
            return;
        
}

    } 

GenerateRnd will Generate random string and check in DB and return the count. I want help in function test(). I want to generate string again if $qryResult == 1. Otherwise continue process. Wethere the present code will enough or any changes need. Please help me.

 
Posted: 19 April 2012 10:26 AM   [ # 1 ]   [ Rating: 0 ]
Joined: 2012-03-10
36 posts

You have missing GenerateRnd() function declaration!

 
Posted: 19 April 2012 10:58 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-04-08
15 posts

I didn’t post GenerateRnd() function. I just want to know return will execute $qryResult = $this->GenerateRnd() or not.

 
Posted: 21 April 2012 02:27 AM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2012-04-18
247 posts

instead of

if($qryResult == 1)
{
  
echo "True";
  return;

do

if($qryResult)
{
   
echo "True";
   return 
$qryResult;

the echo “True”; is not really needed but i am assuming you want to actually print “True” on the screen

 Signature 

CjaxFw for CI,  20,000 downloads in last few months, and growing fast

http://cjax.sourceforge.net/

Follow Me on Twitter @AjaxFramework
https://twitter.com/ajaxframework

Checkout my Blog