Is it possible to pass an array as a command line argument to a PHP script?

前端 未结 9 870
忘掉有多难
忘掉有多难 2020-12-09 16:37

I\'m maintaining a PHP library that is responsible for fetching and storing incoming data (POST, GET, command line arguments, etc). I\'ve just fixed a bug that would not all

9条回答
  •  再見小時候
    2020-12-09 17:00

    As it was said you can use serialize to pass arrays and other data to command line.

    shell_exec('php myScript.php '.escapeshellarg(serialize($myArray)));
    

    And in myScript.php:

    $myArray = unserialize($argv[1]);
    

提交回复
热议问题