1

I'm trying to get this data [label] => For Rent from a multi-dimensional array. Here is my array

Array ( [listing_id] => 0 
        [fields] => 
                   Array ( [1] => Property House 7 [2] => 30 [4] => sdfasd
                           [11] => Bungalow [10] => Philippines [12] => 1800100
                           [13] => 1 [14] => 1 [15] => Yes [16] => Yes [17] => Yes
                           [18] => Yes [26] => Yes [25] => Yes [24] => Yes
                           [23] => Yes [22] => Yes [21] => Yes [20] => Yes [19] => Yes) 
        [fees] => Array ( 
            [30] => stdClass Object ( [id] => 2 [label] => For Rent [amount] => 0.00
                                      [days] => 7 [images] => 0
                                      [categories] => 
                                        Array ( [all] => 0 
                                [categories] => Array ( [0] => 30 ) ) [extra_data] => ) ) 

                                [images] => Array ( ) [thumbnail_id] => 0 )

How will I echo the label that has a value of For Rent using PHP code

2
  • your array contains stdClass Object . How can it possible. Commented Oct 4, 2012 at 5:07
  • 2
    @YogeshSuthar, You can put whatever you want in an array, including object instances. Commented Oct 4, 2012 at 5:08

3 Answers 3

1
echo $yourArray['fees'][30]->label

It's not just an array... it's an array with an object in it. Use the -> to access object properties.

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

2 Comments

so what if I want to echo the 30? in here $yourArray['fees'][30]->label
@KevinSteveManingo, The value of 30 is an object! If you want to echo it, its __toString() method will be called. You probably didn't define one, since it is just a StdObject.
1

Try

$array[fees][30]->label

Where $array is whatever you're top level variable is.

Comments

0

You can access any value of array by their keys. simply access For Rent like this :-

echo $arrayName['fees'][30]->label

This will display For Rent like ( An Arrow operator because to access an object attribute you have to use this )

Comments

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.