Solved

Multi dimension array

Posted on 2011-09-19
2
447 Views
Last Modified: 2012-05-12
I have get value of Multi dimension array. how can get is. My array is mentions below. please refer that and please give me a reply.

I need a value of 8,9 so how can get a both value using PHP?


Array
(
    [field_add_title] => Array
        (
            [#theme] => field
            [#weight] => 0
            [#title] => Title
            [#access] => 1
            [#label_display] => above
            [#view_mode] => full
            [#language] => und
            [#field_name] => field_add_title
            [#field_type] => text
            [#field_translatable] => 1
            [#entity_type] => field_collection_item
            [#bundle] => field_adress
            [#object] => FieldCollectionItemEntity Object
                (
                    [fieldInfo:protected] =>
                    [hostEntity:protected] => stdClass Object
                        (
                            [vid] => 84
                            [uid] => 1
                            [title] => Court Locations
                            [log] =>
                            [status] => 1
                            [comment] => 1
                            [promote] => 0
                            [sticky] => 0
                            [ds_switch] =>
                            [nid] => 83
                            [type] => address
                            [language] => und
                            [created] => 1315574149
                            [changed] => 1316232612
                            [tnid] => 0
                            [translate] => 0
                            [revision_timestamp] => 1316232612
                            [revision_uid] => 1
                            [body] => Array
                                (
                                    [und] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [value] =>
Content Display Here...

                                                    [summary] =>
                                                    [format] => full_html
                                                    [safe_value] =>


Content Display Here...
 


                                                    [safe_summary] =>
                                                )

                                        )

                                )

                            [field_adress] => Array
                                (
                                    [und] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [value] => 8
                                                )

                                            [1] => Array
                                                (
                                                    [value] => 9
                                                )

                                        )


                                )
0
Comment
Question by:naeemsabasara
2 Comments
 
LVL 14

Expert Comment

by:Scott Madeira
ID: 36560827
Perhaps something like:

$variable['field_add_title']['#object']->hostEntity->field_address[und][0]['value']

$variable['field_add_title']['#object']->hostEntity->field_address[und][1]['value']
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 36592642
Suggest you get this book and give yourself a little while to study.  If you are going to tackle problems like this you need to have a sturdy foundation of understanding PHP and MySQL.  This little book will be very helpful.
http://www.sitepoint.com/books/phpmysql4/

I am not sure I understand your question but I will try.  Let's look at this part, taking misspelled English words into account.

                           [field_adress] => Array
                                (
                                    [und] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [value] => 8
                                                )

                                            [1] => Array
                                                (
                                                    [value] => 9
                                                )

                                        )

                                )


What that is telling us is that you have some kind of array or object that contains a variable named field_adress.  Inside that variable is another array named und.  Und is a numerically indexed array.  Inside und there are two associative arrays with keys named value pointing to the 8 and the 9.  It might be hard to find a more confusing data structure.

Since we do not know for sure what the name of the highest-level array or object might be. I will assume that it is an array named $arr.

This would be the way to get the value elements.

foreach ($arr['field_adress']['und'] as $thing)
{
    var_dump($thing['value']);
}
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now