Created
February 2, 2012 10:06
-
-
Save Loupax/1722717 to your computer and use it in GitHub Desktop.
A function I made for use in CodeIgniter, search entire result set and when the match is evaluated, returns the value specified of said row
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
| /** | |
| * Searches a CI resultset, and when the match is evaluated, returns the specified value | |
| * Both params of $match array are required | |
| * | |
| * Example of use: if you want to get the ID of an item where the row 'type' is 'user' | |
| * you do: | |
| * | |
| * Take note: The comparison doesn't take account of whitespace characters before and | |
| * after the data of the result sets rows | |
| * | |
| * get_item_where_key($result, 'id', $array('type' => 'user'); | |
| * | |
| * @param $result_set object | |
| * @param $key string | |
| * @param $match array | |
| * | |
| */ | |
| function get_item_where_key($result_set, $item, $match){ | |
| $key = array_keys($match); | |
| $key = $key[0]; | |
| foreach ($result_set as $row) | |
| { | |
| if(trim($row->$key) == trim($match[$key])) | |
| { | |
| return $row->$item; | |
| } | |
| } | |
| return FALSE; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment