Welcome to Findnerd. We are going to discuss the array function named array_flip which is useful to exchange the keys and its associated values.Please have a look.
<?php
$patients_nfo = array('Deepak'=>23,'Dipti'=>24,'sonak'=>34);
$flip_arr = array_flip($patients_info);
print_r($flip_;arr);
?>
result: array([23]=>'deepak',[24]=>'dipti',[34]=>'sonak');
If you have same values in the array then last value will be added in key. Please have a look.
<?php
$patients_info = array('Deepak'=>23,'Dipti'=>23,'sonak'=>34);
$flip_arr = array_flip($patients_info);
print_r($flip_arr);
?>
result: array([23]=>'dipti',[34]=>'sonak');
0 Comment(s)