如何从图像对象中提取属性

时间:2016-01-01 作者:frosty

php非常新。我有以下var\\u dump($largeImage),其输出如下。

我正在尝试获取缩略图url。

我试过了

$tempLargeImage = $largeImage["url"];
$overlayImage = $tempLargeImage["thumbnail"];
但这是“非法字符串偏移量‘缩略图’”

    array(10) { 
["id"]=> int(440) ["alt"]=> string(0) "" ["title"]=> string(40) "bcd8d0b4d2d97f1889d7fab5d82075d07bfb51e8" ["caption"]=> string(0) "" ["description"]=> string(0) "" ["mime_type"]=> string(10) "image/jpeg" ["url"]=> string(112) "http://a.com/.jpg" ["width"]=> int(1589) ["height"]=> int(2048) ["sizes"]=> array(48) 
{ ["thumbnail"]=> string(120) "http://a.com/-150x150.jpg" ["thumbnail-width"]=> int(150) ["thumbnail-height"]=> int(150) ["medium"]=> string(120) "http://a.com/-233x300.jpg" ["medium-width"]=> int(233) ["medium-height"]=> int(300) ["medium_large"]=> string(112) "http://a.com/.jpg" ["medium_large-width"]=> int(1589) ["medium_large-height"]=> int(2048) ["large"]=> string(121) "http://a.com/-795x1024.jpg" ["large-width"]=> int(795) ["large-height"]=> int(1024) ["portfolio-square"]=> string(120) "http://a.com/-570x570.jpg" ["portfolio-square-width"]=> int(570) ["portfolio-square-height"]=> int(570) ["portfolio-portrait"]=> string(120) "http://a.com/-600x800.jpg" ["portfolio-portrait-width"]=> int(600) ["portfolio-portrait-height"]=> int(800) ["portfolio-landscape"]=> string(120) "http://a.com/-800x600.jpg" ["portfolio-landscape-width"]=> int(800) ["portfolio-landscape-height"]=> int(600) ["menu-featured-post"]=> string(120) "http://a.com/-345x198.jpg" ["menu-featured-post-width"]=> int(345) ["menu-featured-post-height"]=> int(198) ["qode-carousel_slider"]=> string(120) "http://a.com/-400x260.jpg" ["qode-carousel_slider-width"]=> int(400) ["qode-carousel_slider-height"]=> int(260) ["portfolio_slider"]=> string(120) "http://a.com/-500x380.jpg" ["portfolio_slider-width"]=> int(500) ["portfolio_slider-height"]=> int(380) ["portfolio_masonry_regular"]=> string(120) "http://a.com/-500x500.jpg" ["portfolio_masonry_regular-width"]=> int(500) ["portfolio_masonry_regular-height"]=> int(500) ["portfolio_masonry_wide"]=> string(121) "http://a.com/-1000x500.jpg" ["portfolio_masonry_wide-width"]=> int(1000) ["portfolio_masonry_wide-height"]=> int(500) ["portfolio_masonry_tall"]=> string(121) "http://a.com/-500x1000.jpg" ["portfolio_masonry_tall-width"]=> int(500) ["portfolio_masonry_tall-height"]=> int(1000) ["portfolio_masonry_large"]=> string(122) "http://a.com/-1000x1000.jpg" ["portfolio_masonry_large-width"]=> int(1000) ["portfolio_masonry_large-height"]=> int(1000) ["portfolio_masonry_with_space"]=> string(120) "http://a.com/-700x902.jpg" ["portfolio_masonry_with_space-width"]=> int(700) ["portfolio_masonry_with_space-height"]=> int(902) ["latest_post_boxes"]=> string(120) "http://a.com/-539x303.jpg" ["latest_post_boxes-width"]=> int(539) ["latest_post_boxes-height"]=> int(303) } 

}

1 个回复
最合适的回答,由SO网友:Shwan Namiq 整理而成

因为有两个数组,所以第二个数组嵌套在第一个数组中

您必须从sizes 数组不直接来自第一个数组

$overlayImage = $tempLargeImage["sizes"]["thumbnail"];