DevelopPHP
home Forum gear home

Libraries book

HTML Library CSS Library JavaScript Library PHP Library

Videosbook

PHP and MySQL JavaScript HTML and CSS Vector and 3D Flash Actionscript Android Dev Miscellaneous

Resourcesbook

Website Hosting
array_search ( ) - Search an array for a value and return the key where it is found   Share / Like
The array_search() array function in PHP will search in an array for a specific value. If found it will return the corresponding key for that value. It is a good way to check to see if a value exists in an array. Remember that all arrays have a default index of 0, so the first element has a key of 0 when key labels are not specified in the array.

Learn HTML
<?php
$targetArray 
= array("Sara","Cindy","Julie","Megan");
$find "Julie";
$keyFound array_search($find$targetArray);
if (
$keyFound) {
    echo 
"The key where $find was found is: $keyFound";
} else {
    echo 
"$find was NOT FOUND in the array";
}
?>

Develop PHP browser display window
The key where Julie was found is: 2


Home   •   Terms of Use   •   Developer Forums   •   T-Shirts   •   RSS   •   Classroom Chalkboard   •   Donate   •   Top ↑
Popular In PHP / MySQL E-Commerce Store Production
Social Network Website Building
Image Upload / Photo Processing
CMS Software Programming
Mass Email Systems
Magic XML Data
Search Programming
Popular In JavaScript JSON Programming
Ajax Programming
Animating Elements
WYSIWYG Programming
Date/Time Programming
DOM Scripting
Object Reference
Popular In HTML Canvas Element
New Form Elements
Audio Element
Video Element
Drag and Drop
Event Handling
Element Grouping
Popular In CSS Custom Font Embedding
Dynamic Fit Backgrounds
Theatre Mode
Box Overlays
CSS Level 1 Properties
CSS Level 2 Properties
CSS Level 3 Properties
©2013 DevelopPHP   |   Navigate to related domains HTML5