我正在使用此函数将所有可用的图像大小作为数组返回。
function king_image_size() {
$image_sizes = get_intermediate_image_sizes();
foreach ($image_sizes as $tax) {
$image_sizes[$tax] = $tax;
}
return $image_sizes
}
但这会复制返回数组。输出
array(18) { [0]=> string(9) "thumbnail" [1]=> string(6) "medium" [2]=> string(12) "medium_large" [3]=> string(5) "large" [4]=> string(9) "dhaka-por" [5]=> string(11) "dhaka-por-h" [6]=> string(15) "dhaka-landscape" [7]=> string(7) "dhaka-h" [8]=> string(8) "dhaka-sq" ["thumbnail"]=> string(9) "thumbnail" ["medium"]=> string(6) "medium" ["medium_large"]=> string(12) "medium_large" ["large"]=> string(5) "large" ["dhaka-por"]=> string(9) "dhaka-por" ["dhaka-por-h"]=> string(11) "dhaka-por-h" ["dhaka-landscape"]=> string(15) "dhaka-landscape" ["dhaka-h"]=> string(7) "dhaka-h" ["dhaka-sq"]=> string(8) "dhaka-sq" }
另外,我发现很常见,
function king_image_size() {
$image_sizes = get_intermediate_image_sizes();
return $image_sizes;
}
然后我在页面构建器中获得0,1,2,3 ...输出。我需要这个功能像
一样工作function king_image_size(){
return array(
'medium' => 'medium' ,
);
}
答案 0 :(得分:0)
所以你只想要一个使用你得到的值的数组,作为键......?
为此,您只需使用array_combine
,然后只需两次输入值数组:
function king_image_size() {
$image_sizes = get_intermediate_image_sizes();
return array_combine($image_sizes, $image_sizes);
}