Welcome To Infinitbility!
1//indexOf example2var fruits = ['Banana', 'Blackcurrant', 'Blueberry', 'Chili pepper', 'Cranberry', 'Eggplant', 'Gooseberry'];34// You get their index ( Key )5var index = fruits.indexOf('Blueberry');6// output 278// if value not available9var index = fruits.indexOf('Apple');10// output -1
Similarly, Php provides in_array function to find value from an array Understand with an example
1<?php23# inArray example4$fruits = ['Banana', 'Blackcurrant', 'Blueberry', 'Chili pepper', 'Cranberry', 'Eggplant', 'Gooseberry'];56# You get true or false7$result = in_array("Blueberry", $fruits);8# output true910# if value not available11$result = in_array("Apple", $fruits);12# output false1314?>
Thanks for reading…
Follow me on Twitter
Join our email list and get notified about new content
No worries, I respect your privacy and I will never abuse your email.
Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.