从数组中获取特定元素


get a specific element from an array

我有一个数组如下,我想从这个数组中获取任何特定元素:数组存储在变量中。

   $results = 
        Array
           (
        [0] => stdClass Object
                         (
        [id] => 1
        [calendar] => 1
        [time] => 2016-01-22 17:25:28
        [booked_time] => 01/22/2016 11:00
        [booked_time_unformatted] => 2016-01-22 11:00:00
        [name] => Shoaib
        [email] => shoaib@techleadz.com
        [phone] => 0987654321
        [question] => 123
        [quantity] => 1
        [buffered_date] => a:9:{s:5:"PRICE";s:2:"25";s:10:"COUPONCODE";s:0:"";s:8:"QUANTITY";N;s:4:"NAME";s:6:"Shoaib";s:5:"EMAIL";s:20:"shoaib@techleadz.com";s:5:"PHONE";s:10:"0987654321";s:8:"COMMENTS";s:3:"123";s:4:"DATE";s:10:"01/22/2016";s:4:"TIME";s:5:"11:00";}
        [submitted] => 1
    )
[1] => stdClass Object
    (
        [id] => 2
        [calendar] => 1
        [time] => 2016-01-23 10:39:30
        [booked_time] => 01/25/2016 15:00
        [booked_time_unformatted] => 2016-01-25 15:00:00
        [name] => Shoaib
        [email] => shoaib@techleadz.com
        [phone] => 0987654321
        [question] => dsadasd
        [quantity] => 1
        [buffered_date] => a:9:{s:5:"PRICE";s:2:"25";s:10:"COUPONCODE";s:0:"";s:8:"QUANTITY";N;s:4:"NAME";s:6:"Shoaib";s:5:"EMAIL";s:20:"shoaib@techleadz.com";s:5:"PHONE";s:10:"0987654321";s:8:"COMMENTS";s:7:"dsadasd";s:4:"DATE";s:10:"01/25/2016";s:4:"TIME";s:5:"15:00";}
        [submitted] => 1
    )
[2] => stdClass Object
    (
        [id] => 3
        [calendar] => 1
        [time] => 2016-01-23 11:27:22
        [booked_time] => 01/25/2016 11:00
        [booked_time_unformatted] => 2016-01-25 11:00:00
        [name] => test
        [email] => shoaib@techleadz.com
        [phone] => 0987654321
        [question] => asfas
        [quantity] => 1
        [buffered_date] => a:9:{s:5:"PRICE";s:2:"25";s:10:"COUPONCODE";s:0:"";s:8:"QUANTITY";N;s:4:"NAME";s:4:"test";s:5:"EMAIL";s:20:"shoaib@techleadz.com";s:5:"PHONE";s:10:"0987654321";s:8:"COMMENTS";s:5:"asfas";s:4:"DATE";s:10:"01/25/2016";s:4:"TIME";s:5:"11:00";}
        [submitted] => 0
    )
            )

现在我有一个这样的数组,所以我如何获取这个数组中 [submitted] foreach 元素的值。

这不是一个数组。这是一个标准类对象

访问标准类中的信息

 $results[6]->submitted;

要随机访问特定字段,请使用

echo $results[0]->submitted;
echo $results[0]->quantity;
echo $results[1]->submitted;
echo $results[1]->quantity;

使用 foreach 循环

foreach ( $results as $result ) {
    echo $result->submitted . '<br>';  
    echo $result->booked_time . '<br>';
    echo $result->name . '<br>';
    echo $result->time . '<br>';
    echo $result->email . '<br>';
}