SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Return 2 var from 1 function ?!

    Hi ..

    How can I do this, i wanna get to var from 1 function ?

    I mean :

    PHP Code:
    class A
    {
       function 
    abc()
       {
          return 
    $title;
          return 
    $content;
        }
    }
     
    $x= new A();
    $x->abc()
    echo 
    "title = $title";
    echo 
    "content= $content"
    I know what i write above is wrong, but how ?!

  2. #2
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just idea to skip storing the var in session ?!
    Code:
    class A
    {
    function abc()
    {
    $_SESSION['title'] ="HAHAH";
    $content= "AAAAAAa";
    return $content;
    }
    }
    
    
    
    $x= new A();
    $x->abc()
    echo "title = $title";
    echo "content= $content"; 
    


  3. #3
    SitePoint Zealot codezilla's Avatar
    Join Date
    Nov 2002
    Location
    upstairs
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function titleAndContent()
    {
        
    $title 'The Title';
        
    $content 'The content.';
        return array(
    $title$content);
    }

    list(
    $t$c) = titleAndContent();

    // you could also do:
    // $tc = titleAndContent();
    // $t = $tc[0];
    // $c = $tc[1];

    echo "title = $t";
    echo 
    "content= $c"
    or OO:

    PHP Code:
    class A
    {
        var 
    $content 'The content.';
        var 
    $title 'The Title';
        
        function 
    titleAndContent()
        {
            return array(
    $this->title$this->content);
        }
    }

    $x =& new A();
    list(
    $t$c) = $x->titleAndContent();
    echo 
    "title = $t";
    echo 
    "content= $c"
    Last edited by codezilla; Jun 12, 2003 at 12:32.

  4. #4
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, you could return the result as an array, example
    PHP Code:
    class {
      function 
    abc() {
        
    $array['title'] = 'Title';
        
    $array['content'] = 'The mad cow jumped down into the river';
        return 
    $array;
      }
    }

    $x = new A();
    $array $x->abc();
    echo 
    'title = ' $array['title'];
    echo 
    'content = ' $array['content']; 
    Hope this helps
    Edit:

    Damn, too late
    - website

  5. #5
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thx for u both

  6. #6
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or reference ? ...

    PHP Code:
    <?
    class A
    {
       function 
    abc(&$title,&$content)
       {
         
    $title='I am the title';
         
    $content='I am a taxi';
        }
    }

    $x= new A();
    $x->abc($title,$content);
    echo 
    $title.' '.$content
    ?>

  7. #7
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or the evil global option
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  8. #8
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje
    or the evil global option
    *slaps sweatje*
    Oh no! the coots are eating my nodes!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •