Related Links : Search Engine Optimization | | Search Engine Marketing | Online Marketing | Freelance Programmer| SEO Thailand | SEO Expert | SEO services | PHP Programmer Thailand | SEO Tutorial | What is SEO |

  Home Our SEO Services SEO Expert Consultant Php Programmer Keyword Suggestion Scripts|Articles| Email : sachin {at} jainsachin {dot} com

PHP | Returning values | Manual | Tutorial | Help

SEO Services



Website Programming in PHP / MYSQL



SEO Tools




    Friends


      Returning values

      Returning values

      Values are returned by using the optional return statement. Any type may be returned, including arrays and objects. This causes the function to end its execution immediately and pass control back to the line from which it was called. See return() for more information.

      Example #1 Use of return()

      <?php
      function square($num)
      {
          return 
      $num $num;
      }
      echo 
      square(4);   // outputs '16'.
      ?>

      A function can not return multiple values, but similar results can be obtained by returning an array.

      Example #2 Returning an array to get multiple values

      <?php
      function small_numbers()
      {
          return array (
      012);
      }
      list (
      $zero$one$two) = small_numbers();
      ?>

      To return a reference from a function, use the reference operator & in both the function declaration and when assigning the returned value to a variable:

      Example #3 Returning a reference from a function

      <?php
      function &returns_reference()
      {
          return 
      $someref;
      }

      $newref =& returns_reference();
      ?>

      For more information on references, please check out References Explained.


      SEO Tutorial / Articles





      Php / Mysql Tutorial



      Articles



        Other Topics



        SEO by Jainsachin