为foreach()(对象数组)提供无效参数


Invalid argument supplied for foreach() (array of objects)

我什么办法都试过了,怎么也动不了。

我有这个数组($plugins->response):

array (size=1)
  'akismet/akismet.php' => 
    object(stdClass)[108]
      public 'id' => string '15' (length=2)
      public 'slug' => string 'akismet' (length=7)
      public 'plugin' => string 'akismet/akismet.php' (length=19)
      public 'new_version' => string '3.1.3' (length=5)
      public 'url' => string 'https://wordpress.org/plugins/akismet/' (length=38)
      public 'package' => string 'https://downloads.wordpress.org/plugin/akismet.3.1.3.zip' (length=56)

我是这样做的:

foreach($plugins->response as $plugin)
{
    var_dump($plugin);
    $payload['output'] = $payload['output'] . "'rThe plugin : {$plugin->slug} is not up to date";
    $payload['status'] = 1;
}

你知道为什么它不起作用吗?我知道这是最基本的东西,但我保证这不止一个小时。我对PHP很陌生。由于

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>StackOverFlow</title>
</head>
<body>
<?php
class Plugins {
    public $id;
    public $slug;
    public $plugin;
    public function __construct()
    {
        $this->id = '15';
        $this->slug ='akismet';
        $this->plugin = 'akismet/akismet.php';
    }
}
$plugins = new Plugins();
var_dump($plugins);
// We can iterate the $plugins like this:
foreach ($plugins as $key => $val) {
    echo "$key = $val <br/>";
}
   
// If you want to avoid the iteration and refer to a specific
// property of the object (properties are the public 
//$id,$slug,$plugin) of the class: 
   
$payload['output'] = $payload['output'] . "'rThe plugin : {$plugins->slug} is not up to date";
$payload['status'] = 1;
var_dump($payload);
?>
</body>
</html>