Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Multi dimension array

Posted on 2011-09-19
2
Medium Priority
?
473 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 111

Accepted Solution

by:
Ray Paseur earned 1000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

916 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