douhui2307 2016-09-03 07:59
浏览 725
已采纳

如何$ row = mysqli_fetch_assoc($ result),在php中是可能的

We know we can't store a function in variable

<?php
$k = echo("hello");
?>

or

$k = unset($_SESSION['name']);

They all will give error. because we can't store a function in variable directly, but how we can use.

$row = mysqli_fetch_assoc($result);

I know mysqli_fetch_assoc() function output an array which is stored in variable $row . but how a general rule of php is violated. and we are able to store function in a variable

  • 写回答

2条回答 默认 最新

  • dq1230123 2016-09-03 08:10
    关注

    echo and unset are not really functions. If you check the documentation, you'll see that it says:

    Return Values
    No value is returned

    Since no value is returned, you can't assign them to variables.

    mysqli_fetch_assoc() is an ordinary function. And like any other function, you can assign its return value to a variable, or pass it as an argument to another function, or use it in an expression.

    You would have a hard time programming in PHP if you couldn't assign function values to variables. You couldn't write things like:

    $max = max($var1, $var2);
    $current_time = time();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料