php foreach with multidimensional array

后端 未结 12 1661
一向
一向 2020-11-27 05:10

I\'m developing a php app that uses a database class to query mySQL.

the class is here: http://net.tutsplus.com/tutorials/php/real-world-oop-with-php-and-mysql/

12条回答
  •  感动是毒
    2020-11-27 05:24

    This would have been a comment under Brad's answer, but I don't have a high enough reputation.

    Recently I found that I needed the key of the multidimensional array too, i.e., it wasn't just an index for the array, in the foreach loop.

    In order to achieve that, you could use something very similar to the accepted answer, but instead split the key and value as follows

    foreach ($mda as $mdaKey => $mdaData) {
        echo $mdaKey . ": " . $mdaData["value"];
    }
    

    Hope that helps someone.

提交回复
热议问题