Welcome Guest, Not a member yet? Register   Sign In
Reset indexs of an array
#1

[eluser]bhakti.thakkar[/eluser]
Hi all,
I have an application which works a bit like a shopping cart. User can delete any item. Delete is working fine:
Code:
function CostOfSalesDelete($indx){
        $CostOfSalesArr= $this->session->userdata('CostOfSalesArr');
        unset($CostOfSalesArr[$indx]);
        $this->session->set_userdata('CostOfSalesArr',$CostOfSalesArr);

        $this->CostOfSalesView();

//        redirect(base_url().'index.php/files/CostOfSalesView/');
    }

After deleting, i need to re-index the session variable. How can i do it

Thanks
#2

[eluser]bhakti.thakkar[/eluser]
Hi all,
Did not know that this will work so easily like conventional PHP

This is working good
<code>
function resetarray($oldarray){

$newarray = array_values($oldarray);
return $newarray;
}
</code>
#3

[eluser]Colin Williams[/eluser]
What a waste of a function. Why would you not just call array_values() directly.

Like, check out this cool function

Code:
function prrrrrint($str)
{
   $new_string = $str;
   print $str;
}
#4

[eluser]bhakti.thakkar[/eluser]
yes, you are correct. no need of any functions. this could (should be infact) done directly
#5

[eluser]Colin Williams[/eluser]
I've seen people write "CRUD" libraries that literally do nothing other than wrap the Database Abstraction layer. People do weird things. Maybe it's lack of caffeine, IDK...




Theme © iAndrew 2016 - Forum software by © MyBB