php - PHP/作用域——在函数内部设置var,在外部访问而不返回
问题描述
我觉得很愚蠢,但范围每次都让我感到困惑。我也不擅长 PHP。在这种情况下,如何在函数内部设置变量,$httpcode
然后在该函数外部访问它?
<?php
function get_feed() {
$ch = curl_init('someurl');
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); // how to use this anywhere?
// try / catch
curl_close($ch);
}
// later down the page
if ($httpcode == "200") {
// do this
}
?>
解决方案
推荐阅读
- android - 尝试更新进度条时出现致命异常
- java - 将罗马数字转换为整数
- python - 如何使用 Django 设置 cookie?
- delphi - DLL_PROCESS_DETACH 不会被调用?
- python - 根据日期和计数对数据框进行分组和重新排序
- postgresql - PostgreSQL 中的 rank()
- java - 从 P7B 文件中获取证书链
- amazon-web-services - 如何使用 python 和 lambda 函数将 Amazon S3 存储桶与 Akamai NetStorage 同步?
- aws-lambda - 使用 aws describe_log_streams 时出现油门异常
- java - 在excel文件中用jfreechart做一个折线图