Search an element in an array and return the key – PHP

<?php
 $testArray = array(0 => 'value1', 1 => 'value4', 2 => 'value2', 3 => 'value3');
 $key = array_search('value2', $testArray); // $key = 2;
 echo "Key is ".$key ; // 2
?>
Share

Leave a Reply

Your email address will not be published. Required fields are marked *