dongxun7962 2011-09-29 21:38
浏览 41
已采纳

PHP - 将变量传递给函数而不传递之前询问的变量?

Is it possible to pass a variable to function without passing the variables that come before it in the function definition?

For example, if my function looks like this:

function doThis( $v1, $v2, $v3 )
{
    echo $v1.$v2.$v3;
}

Can I then call the function with only some of those variables, like doThis("v1",null,"v3") or some other way?

  • 写回答

6条回答 默认 最新

  • dpspn60064 2011-09-29 21:42
    关注

    Yes, you can do doThis("v1",null,"v3"), if you prepare your function to handle that null argument.

    For example your example will work just fine.

    Or, if it makes sense you can change the order of the arguments so you can set defaults.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line