Jump to content

Replace array value with previous array value (key-1)


s1mpl3

Recommended Posts

Please help me i have stucked here, i want to repalce session array value with previous session array value. Like this:
[code]
for($i=1;$i<=count($_SESSION['counter']);$i++){
  $_SESSION['job_code'][$i]=$_SESSION['job_code'][$i-1];
}
[/code]

but i got the value that i dont want to.
how to fix this problem
Thanks before...

(sorry for my english) ;D
Link to comment
Share on other sites

$stop = count($_SESSION['jobcode']);
for($i=1;$i<=$stop;$i++){
  $_SESSION['job_code'][$i]=$_SESSION['job_code'][$i-1];
}

or you could simply use array_shift($_SESSION['job_code']) - this will remove teh first element of the array and of course make the array one element smaller.
Link to comment
Share on other sites

Still not working  :'(. Ok my problem is actualy how to insert an empty row between another row to table and another row altered automatic and i have an algorithm like this :
[code]
if(isset($_GET['add']) && isset($_GET['row'])):
    $_SESSION['new_count']++;
    $row = $_GET['row'];
    for($i=1;$i<=$_SESSION['new_count];$i++){
        if($i<=$row){
//do nothing just print value who have key = $i

} else if($i==$row+1){
    //Insert blank row

        }else{
//Altred table, and value get from key-1

}
      }
  endif;
[/code]

How to implement that algorithm to PHP code?
Link to comment
Share on other sites

Oh sorry for my english so you not understand what i mean, i try use word to explain that algorithm.

eg. there are 6 row, if user want to add a new row under row 3, so a new value in row 4 is blank and value in row 5 is value  from row 4 before its has new value (blank).

Thanks for your attention ToonMariner
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.