php在cli命令行中运行时怎么传递参数

    xiaoxiao2023-09-29  146

    使用$argc, $argv

    $argv参数数组 $argc参数个数 新建1.php

    <?php echo 'arguments:',"\n"; var_dump($argv); echo "\n"; var_dump($argc); ?>

    不传递任何参数运行1.php

    [root@localhost html]# php /usr/local/nginx/html/test/1.php arguments: array(1) { [0]=> string(32) "/usr/local/nginx/html/test/1.php" } int(1)

    传递参数运行1.php

    [root@localhost html]# php /usr/local/nginx/html/test/1.php a b c arguments: array(4) { [0]=> string(32) "/usr/local/nginx/html/test/1.php" [1]=> string(1) "a" [2]=> string(1) "b" [3]=> string(1) "c" } int(4) You have new mail in /var/spool/mail/root [root@localhost html]#
    最新回复(0)