1

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

1
  • I am printing like this echo $arr[0]['fIndexValue']; echo $arr[0]['fChange']; echo $arr[0]['fPercentChange']; Commented Jan 2, 2018 at 13:08

3 Answers 3

1

convert your object in to array using

$array =  (array) $yourObject;

if you use json_decode than give second parameter true e.g

$array = json_decode($jsonStr,TRUE);

It will return array so no need to typecast(conveting) obj to array

also used operator '->' which help to fetch data from object

Sign up to request clarification or add additional context in comments.

Comments

1

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".

2 Comments

The script stops executing>I am getting a blank page
Updated answer above - does this make more sense?
0

Try this to print the whole thing, assuming your var is $arr:

print_r($arr);

Or for variables

print($arr[0]-->fIndexValue);

3 Comments

fIndexValue,fChange,fPercentChange
print($arr[0]-->fIndexValue);
added the example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.