Home  >  Article  >  Backend Development  >  Mobile app interface programming technology - learn to implement PHP advanced functions

Mobile app interface programming technology - learn to implement PHP advanced functions

WBOY
WBOYOriginal
2016-08-08 09:21:56817browse

  • Function definition and calling method
<code>PHP函数的定义方式:

    <span>1.</span>使用关键字“<span><span>function</span>”开始</span><span>2.</span>函数名可以是字母或下划线开头:<span><span>function</span><span>name</span><span>()</span></span><span>3.</span>在大括号中编写函数体:

    <span><span>function</span><span>name</span><span>()</span></span><span>{
        //函数体
        echo <span>'Eric'</span>;
    }</span>    调用方法为函数名+参数,例如:name();</code>
  • Function that returns a value

    Using the return keyword can make the function return a value. It can return any type including arrays and objects. If return is omitted, the default return value is NULL.

<code><span><span><?php</span><span><span>function</span><span>sum</span><span>(<span>$a</span>, <span>$b</span>)</span> {</span><span>return</span><span>$a</span>+<span>$b</span>;
}
<span>//在这里调用函数取得返回值</span><span>/**
 * 初始化数组函数
 */</span><span><span>function</span><span>initArray</span><span>()</span>{</span><span>$arr</span> = <span>array</span>(<span>'o'</span>=><span>'哦'</span>);
    <span>return</span><span>$arr</span>;
}

<span>$s</span> = sum(<span>1</span>,<span>2</span>);
print_r(<span>$s</span>.<span>'<br>'</span>);

<span>$arr</span> = initArray();
print_r(<span>$arr</span>[<span>'o'</span>]);

<span>?></span></span></span></code>

The above has introduced the mobile app interface programming technology - learning to implement PHP advanced functions, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn