Advertisement
Virajsinh

CodeIgniter row_array And result_array customize

Aug 25th, 2020 (edited)
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. // CodeIgniter row_array() And result_array() Customize
  2.  
  3. //row_array()
  4. $result = $query->row_array();
  5. $remove = array('created_at','updated_at'); // Remove Field Name
  6. $arr_list_removed = array_diff_key($result, array_flip($remove));
  7.  
  8. //row_array()
  9. $allowed = array('first_name','last_name','email','gender'); // allowed Field Name
  10. $arr_list_allowed = array_intersect_key($result, array_flip($allowed ));
  11.  
  12. //result_array()
  13. $result = $query->result_array();
  14. $newArr = array_reduce($result, function($carry, $item){
  15.     $carry[] = [
  16.         "id" => $item['id'],
  17.         "name" => $item['name'],
  18.         "status" => $item['status'],
  19.     ];
  20.     return $carry;
  21. });
  22.  
  23. $array_a = ['a','b','c','d'];
  24. $array_b = ['e','f','a','g'];
  25. $result_a = array_intersect($array_a, $array_b); // Output : array('a');
  26. $result_b = array_diff($array_a, $array_b);  // Output : array('b','c','d');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement