我试图最终从这个对象数组中获取wordpress插件插件和新的版本值。我做了很多研究,尝试了很多例子,但没有一个真正显示这种数组格式。我被索引结构搞糊涂了。感谢您的帮助。
下面是来自未序列化的wordpress数据的数组结构的一个片段。
stdClass Object
(
[last_checked] => 1594309667
[response] => Array
(
[advanced-custom-fields/acf.php] => stdClass Object
(
[id] => w.org/plugins/advanced-custom-fields
[slug] => advanced-custom-fields
[plugin] => advanced-custom-fields/acf.php
[new_version] => 5.8.12
[url] => https://wordpress.org/plugins/advanced-custom-fields/
[package] => https://downloads.wordpress.org/plugin/advanced-custom-fields.5.8.12.zip
[icons] => Array
(
[2x] => https://ps.w.org/advanced-custom-fields/assets/icon-256x256.png?rev=1082746
[1x] => https://ps.w.org/advanced-custom-fields/assets/icon-128x128.png?rev=1082746
)
[banners] => Array
(
[2x] => https://ps.w.org/advanced-custom-fields/assets/banner-1544x500.jpg?rev=1729099
[1x] => https://ps.w.org/advanced-custom-fields/assets/banner-772x250.jpg?rev=1729102
)
[banners_rtl] => Array
(
)
[tested] => 5.4.2
[requires_php] => 5.4
[compatibility] => stdClass Object
(
)
)
[amp/amp.php] => stdClass Object
(
[id] => w.org/plugins/amp
[slug] => amp
[plugin] => amp/amp.php
[new_version] => 1.5.5
[url] => https://wordpress.org/plugins/amp/
[package] => https://downloads.wordpress.org/plugin/amp.1.5.5.zip
[icons] => Array
(
[2x] => https://ps.w.org/amp/assets/icon-256x256.png?rev=1987390
[1x] => https://ps.w.org/amp/assets/icon-128x128.png?rev=1987390
)
[banners] => Array
(
[2x] => https://ps.w.org/amp/assets/banner-1544x500.png?rev=1987390
[1x] => https://ps.w.org/amp/assets/banner-772x250.png?rev=1987390
)
[banners_rtl] => Array
(
)
[tested] => 5.4.2
[requires_php] => 5.6
[compatibility] => stdClass Object
(
)
)
[edit-author-slug/edit-author-slug.php] => stdClass Object
(
[id] => w.org/plugins/edit-author-slug
[slug] => edit-author-slug
[plugin] => edit-author-slug/edit-author-slug.php
[new_version] => 1.7.0
[url] => https://wordpress.org/plugins/edit-author-slug/
[package] => https://downloads.wordpress.org/plugin/edit-author-slug.1.7.0.zip
[icons] => Array
(
[2x] => https://ps.w.org/edit-author-slug/assets/icon-256x256.png?rev=1582213
[1x] => https://ps.w.org/edit-author-slug/assets/icon.svg?rev=1582213
[svg] => https://ps.w.org/edit-author-slug/assets/icon.svg?rev=1582213
)
[banners] => Array
(
[2x] => https://ps.w.org/edit-author-slug/assets/banner-1544x500.png?rev=1581739
[1x] => https://ps.w.org/edit-author-slug/assets/banner-772x250.png?rev=1582213
)
[banners_rtl] => Array
(
)
[tested] => 5.4.2
[requires_php] => 5.6.20
[compatibility] => stdClass Object
(
)
)
[essential-addons-for-elementor-lite/essential_adons_elementor.php] => stdClass Object
(
[id] => w.org/plugins/essential-addons-for-elementor-lite
[slug] => essential-addons-for-elementor-lite
[plugin] => essential-addons-for-elementor-lite/essential_adons_elementor.php
[new_version] => 4.0.4
[url] => https://wordpress.org/plugins/essential-addons-for-elementor-lite/
[package] => https://downloads.wordpress.org/plugin/essential-addons-for-elementor-lite.4.0.4.zip
[icons] => Array
(
[2x] => https://ps.w.org/essential-addons-for-elementor-lite/assets/icon-256x256.png?rev=2285897
[1x] => https://ps.w.org/essential-addons-for-elementor-lite/assets/icon-128x128.png?rev=2285897
)
[banners] => Array
(
[2x] => https://ps.w.org/essential-addons-for-elementor-lite/assets/banner-1544x500.gif?rev=2317134
[1x] => https://ps.w.org/essential-addons-for-elementor-lite/assets/banner-772x250.gif?rev=2317134
)
[banners_rtl] => Array
(
)
[tested] => 5.4.2
[requires_php] => 5.4
[compatibility] => stdClass Object
(
)
)
[gravity-forms-google-analytics-event-tracking/gravity-forms-event-tracking.php] => stdClass Object
(
[id] => w.org/plugins/gravity-forms-google-analytics-event-tracking
[slug] => gravity-forms-google-analytics-event-tracking
[plugin] => gravity-forms-google-analytics-event-tracking/gravity-forms-event-tracking.php
[new_version] => 2.3.10
[url] => https://wordpress.org/plugins/gravity-forms-google-analytics-event-tracking/
[package] => https://downloads.wordpress.org/plugin/gravity-forms-google-analytics-event-tracking.2.3.10.zip
[icons] => Array
(
[2x] => https://ps.w.org/gravity-forms-google-analytics-event-tracking/assets/icon-256x256.png?rev=1777199
[1x] => https://ps.w.org/gravity-forms-google-analytics-event-tracking/assets/icon-128x128.png?rev=1777199
)
[banners] => Array
(
[2x] => https://ps.w.org/gravity-forms-google-analytics-event-tracking/assets/banner-1544x500.png?rev=1777199
[1x] => https://ps.w.org/gravity-forms-google-analytics-event-tracking/assets/banner-772x250.png?rev=1777199
)
[banners_rtl] => Array
(
)
[upgrade_notice] => <p>Prevent empty values to be sent to analytics when using partial entries.</p>
[tested] => 5.4.2
[requires_php] => 5.6
[compatibility] => stdClass Object
(
)
)我尝试了一下,但是得到的错误是slug和新版本都是一个未定义的索引。
foreach($plugins_us as $item) {
echo $item['slug'];
echo $item['new_version'];
// to know what's in $item
echo '<pre>'; var_dump($item);
}发布于 2020-07-11 21:38:41
您试图从中获取这些值的对象不是一个数组,而是一个通用对象,这就是为什么您不能使用其索引访问值的原因。尝试将它们作为类的属性进行访问:
echo $item->slug;
echo $item->new_version;https://stackoverflow.com/questions/62849174
复制相似问题