PHP array_search() ফাংশন
উদাহরণ
অ্যারেতে "red" কীমান অনুসন্ধান করুন এবং তার কীমান ফিরিয়ে দেওয়া হবে:
<?php $a=array("a"=>"red","b"=>"green","c"=>"blue"); echo array_search("red",$a); ?>
সংজ্ঞা ও ব্যবহার
array_search() ফাংশন একটি অ্যারেতে কোনও কীমান অনুসন্ধান করে, এবং এর সাথে সম্পর্কিত কীমান ফিরিয়ে দেয়।
বিস্তারিত ব্যাখ্যা
array_search() ফাংশন এবং in_array() একইভাবে, একটি অ্যারেতে একটি কীমান অনুসন্ধান করুন। যদি সেই মান পাওয়া যায়, তবে ম্যাচ হওয়া ইলেকট্রনের কীমান ফিরিয়ে দেওয়া হবে। যদি পাওয়া যায় না, তবে false ফিরিয়ে দেওয়া হবে。
Before PHP 4.2.0, the function returned null instead of false on failure.
If the third parameter strict If specified as true, only the key name of the corresponding element is returned when both the data type and value are consistent.
Syntax
array_search(value,array,strict)
Parameter | Description |
---|---|
value | Required. Specifies the key value to be searched. |
array | Required. Specifies the array to be searched. |
strict |
Optional. If this parameter is set to TRUE, the function searches for elements in the array that match both the data type and value.
If set to true, the type of the given value is checked in the array, the number 5 and the string 5 are different (see example 2). |
Technical Details
Return Value: |
If the specified key value is found in the array, the corresponding key name is returned, otherwise FALSE is returned. If the key value is found more than once in the array, the key name matching the first found key value is returned. |
PHP Version: | 4.0.5+ |
Update Log: |
If invalid parameters are passed to the function, the function returns NULL (this applies to all PHP functions since PHP 5.3.0). Since PHP 4.2.0, if the search fails, the function returns FALSE instead of NULL. |
More Examples
Example 1
Search for key value 5 in the array and return its key name (note ""):
<?php $a=array("a"=>"5","b"=>5,"c"=>"5"); echo array_search(5,$a,true); ?>