dir.by  
  Search  
Programming, development, testing
PHP (язык программирования для быстрого написания Web сайта)
Look for an element in an array in PHP | array_search
  Looked at 620 times    
 Look for an element in an array in PHP | array_search 
last updated: 2 December 2024
To find an element in an array in PHP, use the array_search method
The method will return the index of the element.
If the item is not found, the method will return false
  PHP  
$my_arr1 = array();

$my_arr1[] = "Hello";
$my_arr1[] = "Home";
$my_arr1[] = "Good";

$index = array_search("Home", $my_arr1);
if ($index == false)
     echo "not found";
else
     echo $index;
// On the screen we will see 1

$index = array_search("Car", $my_arr1);
if ($index == false)
     echo "not found";
else
     echo $index;
// On the screen we will see not found
 
← Previous topic
Array in PHP (Create an array, add elements, the length of the array, go through all the elements in the array)
 
Next topic →
Array (key-value) in PHP (Create an array, add elements, the length of the array, go through all the elements in the array)
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

  Объявления  
  Объявления  
 
PHP Study
Что такое PHP ?
Function
Function in PHP. Example: function CalculateSum($value1, $value2) { ... }
Passing parameters by value and by reference to a function in PHP
Pass a function as a parameter to a function | PHP
Unnamed function
Anonymous function (no name). Function pointer in PHP
Pass the unnamed function as a parameter to the | using use (...) the unnamed function sees the variable above | PHP
Arrays
Array in PHP (Create an array, add elements, the length of the array, go through all the elements in the array)
Look for an element in an array in PHP | array_search
Key-value arrays
Array (key-value) in PHP (Create an array, add elements, the length of the array, go through all the elements in the array)
Regular expressions
Регулярные выражения
PHP Server
Create an html file and javascript sends a post request to the php server. PHP server makes the answer | Why on php server $_REQUEST or $_POST array is empty
Framworks (frameworks)
Zend Framework (PHP framework)
Yii (PHP framework)
CakePHP (framework)

  Ваши вопросы присылайте по почте: info@dir.by  
Яндекс.Метрика