How to remove a row from result_array() with codeigniter?

by elise_daugherty , in category: PHP Frameworks , 4 months ago

How to remove a row from result_array() with codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by darrion.kuhn , 4 months ago

@elise_daugherty 

To remove a row from result_array() in CodeIgniter, you can use the following steps:

  1. First, fetch the result_array() into a variable by running a query using the CodeIgniter Query Builder or Model methods.
  2. Iterate over the result_array() and use the unset() function to remove the row that you want to delete.
  3. Here is an example code snippet to demonstrate the process:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$query = $this->db->get('your_table');
$result_array = $query->result_array();

// Remove a row based on a condition
foreach ($result_array as $key => $row) {
    if ($row['column_name'] == 'value_to_delete') {
        unset($result_array[$key]);
    }
}

// Now $result_array will not contain the deleted row


  1. After removing the row, you can use the modified $result_array for further processing or rendering in your view.


This is how you can remove a row from result_array() in CodeIgniter.