duanci3845 2010-12-18 03:19
浏览 20
已采纳

代码点火器form_input

A couple questions here..

  1. What is the following syntax?
  2. What do all the pieces mean?

    (( ! is_array($data)) ? $data : '')
    
  3. How is it used in the function at the end?

    function form_input($data = '', $value = '', $extra = '')
    {
        $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value);
        return "<input "._parse_form_attributes($data, $defaults).$extra." />";
    }
    

Thankyou. Blake

  • 写回答

4条回答 默认 最新

  • dongzhi9906 2010-12-18 03:33
    关注

    Ok let me try as far as I understand you question.

    What is the following syntax?

    It is a function definition.

    What do all the pieces mean?

    This is the ternary operator. It means: If $data is not an array (!is_array($data)), return $data (? $data) otherwise return an empty string (: '')

    It is a shorthand for if-else.

    How is it used in the function at the end?

    Not sure what you mean here. A function _parse_form_attributes($data, $defaults) is called witch seems to return a string.

    If it in your question refers to $defaults, then it is just an array that gets build and that contains the following values:

    Array (
        'type' => 'text',
        'name' => $data, // or empty string if $data is an array,
        'value' => $value
    );
    

    It is used to build an input element, that will look like this:

    <input type="text" 
           name="(value of $data or empty)" 
           value="(value of $value)"
           (value of $extra)
           />
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?