Solved

Multi dimension array

Posted on 2011-09-19
2
453 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 109

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

820 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