'Remove one index from the array in codeigniter controller

Array ( 
    [issuer_id] => in.gsvm 
    [org_id] => 00738648 
    [doc_type] => ABCDS 
    [RROLL] => 12589 
    [YEAR] => 2020 
)

I want to remove org_id from array and store that data in another variable



Solution 1:[1]

You can use unset().

php > $array = Array (0 => 123, 1 => 456);
php > unset($array[0]);
php > print_r($array);
Array
(
    [1] => 456
)

It destroys the variable, which in this case is the array item matching the index that you want to delete.

You assign the value to a new variable before removing it.

php > $array = Array (0 => 123, 1 => 456);
php > $v = $array[0];
php > unset($array[0]);
php > print_r($array);
Array
(
    [1] => 456
)
php > echo $v;
123

Solution 2:[2]

Store the value in a variable:

$orgId = $array['org_id'];

and remove it from the array:

unset($array['org_id']);

This is just ordinary PHP which works the same in CodeIgniter.

Solution 3:[3]

You can use unset(array) method of PHP programming language to remove an item. for example

$dataArray = ['key1'=>'data1','key2'=>'data2'];

unset($dataArray['key1']);

Then pass the array to insert function.

$this->db->insert('table_name',$dataArray);

You can find details example on this link: https://www.techiedelight.com/remove-elements-array-php/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cEz
Solution 2
Solution 3 Nazrul Chowdhury