Php 如何提取JSON值并为每个值运行带有curl的for循环?

Php 如何提取JSON值并为每个值运行带有curl的for循环?,php,json,bash,curl,Php,Json,Bash,Curl,我有一个类似这样的json { "results": [{ "id": 50672, "adult": false }, { "id": 281298, "adult": false }, { "id": 567604, "adult": false }], "page": 1, "total_pages": 1, "total_results": 1 } 要提取id值并对for循环中的每个值运行一个curl,可能类似于 for i in "${

我有一个类似这样的json

{
"results": [{
    "id": 50672,
    "adult": false
}, {
    "id": 281298,
    "adult": false
}, {
    "id": 567604,
    "adult": false
}],
"page": 1,
"total_pages": 1,
"total_results": 1
}
要提取id值并对for循环中的每个值运行一个curl,可能类似于

for i in "${arr[@]}"
  do
    curl -O "https://localhost/$i"
  done

在php…或bash中,这无关紧要

在php中,您可以简单地:

foreach(json_decode($json)->results as $result) {
    $content = file_get_contents("https://localhost/script.php?id=" . $result->id);
    // do something with $content e.g. file_put_contents("filename", $content);
}