简体   繁体   中英

How to echo values from multidimensional array which is in key value pair using php

I have multidimensional array which contain values from database table but values are key value format so i tried to print using forloop and foreach loop but unable to get output ,so how to do this using php forloop or foreach loop?

Values from array

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [Email] => xyz@gmail.com
                    [mobile] => 123456
                    [address] => 'xyz xyz'
                    [maritalstatus] => 'married'

                    [Role] => 'employee'

                )

            [1] => Array
                (
                    [joiningdate] => 2012-11-01
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [Email] => abc@gmail.com
                    [mobile] => 123456
                    [address] => 'xyz xyz'

                    [maritalstatus] => 'married'
                    [Role] => 'employee'


                )

            [1] => Array
                (
                    [joiningdate] => 2012-11-01
                )

        )

        )

print values using forloop

for ($x = 0; $x < count($rows); $x++) {

                            echo '<tr>';
                            foreach ($rows[$x][0] as $key => $value) {

                                $indexposition = array_search($key, array_keys($rows[$x][0]));


                            }
                            echo '</tr>';
                            }

如果您只想打印数组,请使用var_dump($ your_variable)另一个明智的做法:

Finally got solution by simple way. Suppose we are getting all this array from $rows then

for ($x = 0; $x < count($rows); $x++) {

$mergearray = array_merge($rows[$x][0], $rows[$x][1]);

  foreach ($mergearray as $key => $value) {

//Here echo  your values i. $value;
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM