Return a little usage of the array in PHP

Source: Internet
Author: User

This article explains the return value of the PHP function returned from the learning experience.

Returns a value inside the function with return or NULL to end the function's run. However, when you return an array, you can also use Print_r directly inside the function to print. But generally do not do so.

Take an example of an article:

can also be implemented as follows:

<span style= "Font-family:microsoft yahei;font-size:14px;" ><? PHP      function Bubble ($array) {           $len = count ($array);           if ($len <= 1)           {return $array;}           for ($i = 0; $i < $len; $i + +) {for                 ($j = $len-1; $j > $i; $j-) {                      if ($array [$j] < $array [$j-1]) {                            $tmp = $ar ray[$j];                            $array [$j] = $array [$j-1];                            $array [$j-1] = $tmp;                      }                 }           }           Print_r ($array);       }             $array =array (' A ', ' B ', ' C ', ' e ', ' d ', ' G ', ' f ');      Bubble ($array);     ? ></span>


However, it is better to use the previous article when invoking this:

<span style= "Font-family:microsoft yahei;font-size:14px;" > $a =bubble ($array); Print_r ($a);</span>


Return a little usage of the array in PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.