PHP中的基本数组迭代

时间:2019-03-16 11:44:08

标签: php arrays

我有一个格式如下的数组(浏览器中的consol.log)。我将如何在php中迭代数组?

stdClass Object
(
    [SIEcat7] => stdClass Object
        (
            [text] => test1
            [amount] => 1 000.00

        )

    [SIEcat8] => stdClass Object
        (
            [text] => test2
            [amount] => 0.00

        )



)

2 个答案:

答案 0 :(得分:0)

现在就拿

foreach($data as $i => $item) {

}

答案 1 :(得分:0)

您可以在下面尝试。

<?php 
    foreach ($array as $key => $arr){
        echo 'Key: ' , $key, '<br>'; #This will print the keys SIEcat7, SIEcat8
        echo 'Text: ', $arr->text, '<br>';
        echo 'amount: ', $arr->amount, '<br> -------- <br>';
    }
?>