在php开发中,预定义数组是程序员们经常使用的数据结构之一。php中的预定义数组在变量名前面使用一个特殊字符来表示,例如:$_get、$_post、$_cookie都是php预定义数组。不过,有时候我们会遇到一些不是php预定义数组的数组,对于这些不同寻常的数组,我们该怎么处理呢?本文将为您介绍一些非预定义数组。
$var1 = 'Hello';
$var2 = 'World';
function myFunc() {
echo $GLOBALS['var1'] . ' ' . $GLOBALS['var2'];
}
myFunc(); // 输出:Hello World$fileContent = file_get_contents('http://www.example.com/');
print_r($http_response_header);
// 输出:
// Array
// (
// [0] => HTTP/1.1 200 OK
// [1] => Date: Thu, 23 Sep 2021 13:28:50 GMT
// [2] => Server: Apache
// [3] => X-Powered-By: PHP/7.4.23
// ...
// )php myScript.php arg1 arg2 arg3
脚本中可以通过$argc和$argv来获取参数信息:
<?php // myScript.php echo "参数个数:" . $argc . "\n"; echo "参数列表:"; print_r($argv); ?>
输出:
参数个数:4
参数列表:Array
(
[0] => myScript.php
[1] => arg1
[2] => arg2
[3] => arg3
)$fileHandle = fopen('not-exist-file.txt', 'r');
if (!$fileHandle) {
echo $php_errormsg;
}输出:"fopen(not-exist-file.txt): failed to open stream: No such file or directory"
总结
以上就是PHP中的一些非预定义数组,包括:$GLOBALS、$HTTP_RAW_POST_DATA、$http_response_header、$argv、$argc和$php_errormsg。了解这些数组的用途可以帮助我们更好地进行PHP编程。
立即学习“PHP免费学习笔记(深入)”;
以上就是php的一些非预定义数组的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号