[英]get array value from std object in php
I have an array like below. 我有一个像下面的数组。 I want to extract the values . 我想提取值。 Help me out please. 请帮帮我。 But this doesn't print anything. 但这不会打印任何内容。 Please help me.Any help would be appreciated.May you all find this question similar.But I am unable to find any answer,because that's the way we do to find the array values. 请帮助我。任何帮助将不胜感激。也许大家都发现这个问题类似。但是我找不到任何答案,因为这是我们查找数组值的方法。
Array
(
[0] => stdClass Object
(
[bHeader] => stdClass Object
(
[ei] => NSE
[seg] => I
)
[cNetChangeIndicator] =>
[fClosingIndex] => 10558.5
[fHighIndexValue] => 10532
[fIndexValue] => 10469
[fLowIndexValue] => 10438.5
[fOpeningIndex] => 10499.5
[fPercentChange] => -0.85
[sIndexName] => 962450
[fChange] => -89.5
[iIdxId] => 311
)
)
Thanks in advance 提前致谢
You are accessing the object in the array as if it is also an array. 您正在访问数组中的对象,就好像它也是一个数组一样。
You need to access the object's properties using ->
您需要使用->
访问对象的属性
echo $arr[0]->fIndexValue;
echo $arr[0]->fChange;
echo $arr[0]->fPercentChange';
For example: 例如:
$obj = new stdClass;
$obj->fIndexValue = 10469;
$arr = array();
$arr[0] = $obj;
echo $arr[0]->fIndexValue;
Prints "10469". 打印“ 10469”。
convert your object in to array using 使用转换您的对象到数组
$array = (array) $yourObject;
if you use json_decode than give second parameter true eg 如果您使用json_decode而不是给第二个参数true例如
$array = json_decode($jsonStr,TRUE);
It will return array so no need to typecast(conveting) obj to array 它将返回数组,因此无需将obj转换为数组
also used operator '->' which help to fetch data from object 还使用了运算符'->'来帮助从对象中获取数据
Try this to print the whole thing, assuming your var is $arr: 假设您的var是$ arr,请尝试执行以下操作以打印整个内容:
print_r($arr);
Or for variables 或用于变量
print($arr[0]-->fIndexValue);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.