php true or false,Logical operators php true or false

PHP is a loosely typed language. == match the both values and === match the values as well as the data type of values.

if (8 == '8') // returns true

Above condition just match the values not the data type hence if evaluate to TRUE

if (8 === '8') // returns false

and this one check both value and data type of values hence this if evaluate to FALSE

you use === where you want to check the value and data type both and use == when you need to compare only values not the data type.

In your case,

The stripos returns the position of the sub string in the string, if string not found it returns FALSE.

if ( stripos($post_to_check->post_content, '[' . $shortcode) !== false )

The code above check sub string inside string and get evaluate to TRUE only when the sub string found.

If you change it to

if ( stripos($post_to_check->post_content, '[' . $shortcode) != false )

and when the sub string found at the 0 position the if evaluate to FALSE even when sub string is there in the main string.

Then the condition will become like this

if ( 0 != false )

and this will evaluate to FALSE because the 0 is considered as FALSE

So you have to use there !==

if ( 0 !== false )

This will compare the values and data type of both values

The value 0 is an integer type and the false is boolean type, hence the data type does not match here and condition will be TRUE

PHP manual page states these comparison operator you should check this once.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值