stream_context_get_options
リソースフロー/パケット/コンテキストのパラメーターを取得します
関数名:stream_context_get_options()
関数の説明:stream_context_get_options()関数は、指定されたコンテキストのオプションの配列を返します。
適用バージョン:PHP 4> = 4.3.0、PHP 5、PHP 7
使用法:stream_context_get_options(resource $ stream_or_context):array
パラメーター:
戻り値:この関数は、指定されたコンテキストのオプションを含む連想配列を返します。
例:
// 创建一个上下文$context = stream_context_create([ 'http' => [ 'method' => 'POST', 'header' => 'Content-Type: application/json', 'content' => json_encode(['name' => 'John', 'age' => 30]) ] ]); // 获取上下文的选项$options = stream_context_get_options($context); // 输出选项数组print_r($options);
出力:
Array ( [http] => Array ( [method] => POST [header] => Content-Type: application/json [content] => {"name":"John","age":30} ) )
上記の例では、最初にHTTPリクエストのオプションを含むstream_context_create()関数を使用してコンテキストを作成します。次に、stream_context_get_options()関数を使用して、コンテキストのオプションを取得し、$ options変数に保存します。最後に、print_r()関数を使用して、$ optionsアレイの内容を印刷して、コンテキストのオプションを確認します。
出力の結果では、オプション配列にHTTPキーが含まれており、対応する値は連想配列であり、リクエストメソッド、リクエストヘッダー、リクエストボディコンテンツなどのHTTP要求に関連するオプションが含まれていることがわかります。