[英]Accessing array values in PHP
Please can someone tell me what I am doing wrong? 请有人能告诉我我做错了吗? I am trying to retrieve all the data in the array below in PHP and I am having problems doing this.
我正在尝试在PHP中检索下面数组中的所有数据,并且在执行此操作时遇到了问题。 Here is the example:
这是示例:
<?php
$url = 'http://www.example.com/';
if (!$fp = fopen($url, 'r')) {
trigger_error("Unable to open URL ($url)", E_USER_ERROR);
}
$meta = stream_get_meta_data($fp);
print_r($meta);
foreach($meta as $key=>$value) {
echo '<br>'.$value;
}
fclose($fp);
?>
The foreach loop above permit me to loop through and retrieve all the data in the array, but my questions are: 上面的foreach循环允许我循环遍历并检索数组中的所有数据,但是我的问题是:
[wrapper_type]
and other values independently? [wrapper_type]
的值http和其他值? [wrapper_data] => Array
without retrieving all the values together? [wrapper_data] => Array
一个值而又不检索所有值? This is pretty basic stuff; 这是非常基本的东西。 you may want to do some reading up on PHP basics before progressing further.
您可能需要在进一步学习之前阅读一些PHP基础知识。 Nevertheless...
不过...
How can I retrieve only the value http of [wrapper_type] and other values independently?
如何仅单独检索[wrapper_type]的值http和其他值?
$type = $meta["wrapper_type"];
echo $type;
How can I retrieve only one value of [wrapper_data] => Array without retrieving all the values together?
如何只检索[wrapper_data] =>数组的一个值而又不检索所有值?
$the_fourth_header = $meta["wrapper_data"][4];
echo $the_fourth_header;
How can I retrieve only the value http of [wrapper_type]
如何只检索[wrapper_type]的值http
Just with $meta['wrapper_data']
只需
$meta['wrapper_data']
How can I retrieve only one value of [wrapper_data]
如何只检索[wrapper_data]的一个值
The same, Array elements can be accessed using the array[key] syntax: $meta['wrapper_data'][0]
, $meta['wrapper_data'][1]
, ... 可以使用array [key]语法访问相同的Array元素:
$meta['wrapper_data'][0]
, $meta['wrapper_data'][1]
,...
just use 'wrapper_type' index in your array($meta). 只需在数组($ meta)中使用'wrapper_type'索引。
$type = $meta["wrapper_type"];
echo $type;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.