You can search a given value in an array and return the relevant key using array_search()
<?php
$array = array(0 => 'Tom', 1 => 'Kusal', 2 => 'Jerry', 3 => 'Jhonny');
$key = array_search('Tom', $array);
echo $key; // $key = 0;
/* sample
$key = array_search('Kusal', $array); // $key = 1;
$key = array_search('Jerry', $array); // $key = 2;
$key = array_search('Jhonny', $array); // $key = 3;
sample */
?>
Get Free Sinhala IT Learning Videos Kuppiya.com
No comments:
Post a Comment