我想在循环外使用我的新数组。 我该怎么办?
$new = array();
foreach ($array as $data) {
$url = $data["result"]["url"];
$name = $data["result"]["name"];
$new = array(
$name => $url
);
}
print_r($new);
答案 0 :(得分:1)
代替
$new = array(
$name => $url
);
将其编辑为
$new[$name] = $url;
所以它会像这样结束
$new = array();
foreach ($array as $data) {
$url = $data["result"]["url"];
$name = $data["result"]["name"];
$new[$name] = $url;
}
print_r($new);