每个类和数组的PHP [重复]

问题描述 投票:0回答:2

这个问题在这里已有答案:

我的阵列

Array ( 
    [0] => stdClass Object ( 
        [name] => name
        [title] => -- 
        [description] => No
        [url] => http://google.com
        [updated] => 1553419890 ) 
    [1] => stdClass Object ( 
        [name] => Hey
        [title] => Title
        [description] => Yes
        [url] =>  http://twitter.com
        [updated] => 1553321131 ) 
)

如何为每个数组循环上面的数组?

php for-loop each
2个回答
0
投票

//表示数组中的数组

foreach(name_of_your_array as array) { data = array["name"]; }

//对于数组中的对象

foreach(name_of_your_array as array) { data = array->name; } 是你如何做的一个例子


0
投票

我想你正在寻找如何使用键值对格式循环数组

foreach($name_of_your_records_array As $key => $ object)
{
    $count_of_record = $key;
    $name = $object->name;
    $title = $object->title;
    //...
}

参考链接:

PHP manual foreach

Accessing object inside an array PHP

© www.soinside.com 2019 - 2024. All rights reserved.