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

前端 未结 9 865
忘掉有多难
忘掉有多难 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:05

    Directly not, all arguments passed in command line are strings, but you can use query string as one argument to pass all variables with their names:

    php myscript.php a[]=1&a[]=2.2&a[b]=c
    
    
    
    /*
    array(3) {
      [0]=> string(1) "1"
      [1]=> string(3) "2.2"
      ["b"]=>string(1) "c"
    }
    */
    

提交回复
热议问题