note 124213 added to function.in-array

From: Date: Fri, 20 Sep 2019 11:15:29 +0000
Subject: note 124213 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-212254@lists.php.net to get a copy of this message
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. ---- Server IP: 208.43.231.9 Probable Submitter: 195.138.250.34 (proxied: 203.223.190.141) ---- Manual Page -- http://php.net/manual/en/function.in-array.php Edit -- https://master.php.net/note/edit/124213 Del: integrated -- https://master.php.net/note/delete/124213/integrated Del: useless -- https://master.php.net/note/delete/124213/useless Del: bad code -- https://master.php.net/note/delete/124213/bad+code Del: spam -- https://master.php.net/note/delete/124213/spam Del: non-english -- https://master.php.net/note/delete/124213/non-english Del: in docs -- https://master.php.net/note/delete/124213/in+docs Del: other reasons-- https://master.php.net/note/delete/124213 Reject -- https://master.php.net/note/reject/124213 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#212254) next »