相关疑难解决方法(0)

PHP - 退出或返回哪个更好?

我想知道在以下情况下哪个是更好的选择:

在PHP脚本中,如果$fileSize变量大于100,我停止脚本;

案例I:

<?php
if ( $fileSize > 100 )
{
   $results['msg'] = 'fileSize is too big!';
   echo json_encode( $results );
   exit();
}
Run Code Online (Sandbox Code Playgroud)

案例二:

<?php
if ( $fileSize > 100 )
{
   $results['msg'] = 'fileSize is too big!';
   exit( json_encode( $results ) );
}
Run Code Online (Sandbox Code Playgroud)

案例III:

<?php
if ( $fileSize > 100 )
{
   $results['msg'] = 'fileSize is too big!';
   return( json_encode( $results ) );
}
Run Code Online (Sandbox Code Playgroud)

上面三(3)个选项中哪一个最好?

php terminate

46
推荐指数
3
解决办法
5万
查看次数

标签 统计

php ×1

terminate ×1