Created
December 17, 2024 06:27
-
-
Save shohag-cse-knu/270882ffd6be99c35442808c78b583f0 to your computer and use it in GitHub Desktop.
Array column search in 2D array and return the index and it's corresponding parameters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $arr_dist_sro = array( | |
| array('id'=>127, 'district'=>'field_6', 'sro'=>'field_9'), | |
| array('id'=>128, 'district'=>'field_6', 'sro'=>'field_7'), | |
| array('id'=>133, 'district'=>'field_4', 'sro'=>'field_6'), | |
| array('id'=>136, 'district'=>'field_6', 'sro'=>'field_7'), | |
| array('id'=>145, 'district'=>'field_4', 'sro'=>'field_5') | |
| ); | |
| $search_id = 133; | |
| if(array_search($search_id, array_column($arr_dist_sro, 'id')) !== false){ | |
| //Index of 133. Such as it's index is 2 | |
| $index = array_search($search_id, array_column($arr_dist_sro, 'id')); | |
| $district = $arr_dist_sro[$index]['district']; | |
| $sro = $arr_dist_sro[$index]['sro']; | |
| echo $district." ".$sro; | |
| } | |
| //This wil print the district and sro of 133 id | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment