我正在检查一个wordpress主题代码,我找到了这行代码:
840 <= $width && $sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px';
这行在php方面意味着什么?
更清楚,这是整个功能:
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for content images
*
* @since Twenty Sixteen 1.0
*
* @param string $sizes A source size value for use in a 'sizes' attribute.
* @param array $size Image size. Accepts an array of width and height
* values in pixels (in that order).
* @return string A source size value for use in a content image 'sizes' attribute.
*/
function twentysixteen_content_image_sizes_attr( $sizes, $size ) {
$width = $size[0];
840 <= $width && $sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px';
if ( 'page' === get_post_type() ) {
840 > $width && $sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
} else {
840 > $width && 600 <= $width && $sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px';
600 > $width && $sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
}
return $sizes;
}
答案 0 :(得分:3)
检查条件并设置变量,以防它变为真。
就像说:
conditionA && $variable="value";
在你的情况下,就像是说:
if (840 <= $width) {
$sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px';
}
看一点测试:
<?php
$a=3;
$v=0;
echo "v = $v\n";
$a == 3 && $v = "hello";
echo "v = $v";
如果你执行它,你会得到:
v = 0
v = hello
答案 1 :(得分:0)
就像这样:
840 <= $width && $sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px';
是
conditionA && conditionB
等于
if( conditionA && conditionB ){}
或
if( conditionA ) { conditionB }
与
相同conditionA || conditionB
喜欢
if( conditionA || conditionB ){}
例如
$a = 1;
$b = 0;
// if( $a == 2 && $b = 3 ){}
$a == 2 && $b = 3; // && do not exec $b = 3,becuase $a != 2
echo $a,' ',$b; // 1 0
// if( $a == 1 && $b = 4 ){}
$a == 1 && $b = 4; // exec $b = 4,becuase $a == 1
echo $a,' ',$b; // 1 4
// if( $a == 1 && $b = 4 ){}
// and how about ||
$a = 1;
$b = 0;
// if( $a == 1 || $b = 3 ){}
$a == 1 || $b = 3; // && do not exec $b = 3,becuase $a == 1
echo $a,' ',$b; // 1 0
// if( $a == 2 || $b = 4 ){}
$a == 2 || $b = 4; // exec $b = 4,becuase $a == 1 not 2
echo $a,' ',$b; // 1 4