php in_array 0,PHP: in_array - Manual

In PHP array function the in_array() function mainly used to check the item are available or not in array.

In_array() Syntax:

in_array( 'search_item' , $array, boolean)

Where,

boolean - It is used to check strict validation. And this field is optional one. If you want the strict validation you can use this.

We using in_array() function to performing following following two function. That is ,

1. Non-strict validation

2. Strict validation

1. Non-strict validation:

This method to validate array with some negotiation. And it allow two parameters.

For example,

$array_sample = array (  'key1' => 567 , 'key2' => 579);

in_array('key1', $array_sample);   // output1:  true

in_array('577', $array_sample, false);   // output2:  true

Note: the Example 1, we use only two parameter. Because we can't mention `false` value. Because In default the in_array() take `false` as a boolean value.

In above example,

Example 1 : The `key1` is not value in the array.    This is key of the array. So this scenario the in_array accept the search key as a value of the array.

Example 2: The value `577` is not in the value and key of the array. It is some similar to the value `579`. So this is also accepted.

So this reason this type is called non-strict function.

2. Strict validation

This method to validate array without any negotiation. And it have three parameters. If you only mention two parameter the `in_array()` function take as a non-strict validation.

For example,

$array_sample = array (  'key1' => 567 , 'key2' => 579);

in_array('key1', $array_sample , true);   // output1:  false

in_array('577', $array_sample, true);   // output2:  false

This is return `true` only the search string is match exactly with the array value with case sensitivity.

Thanks for your time.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值