+ Reply to Thread
Results 1 to 2 of 2

Thread: Shifting Array values

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    35

    Shifting Array values

    I have an array that has ID => Value and all i need is to shift the ID and Value from the
    begining of the array to the end and keep the ID , example :
    Code:
    $fields = array ("1" => "V1", "2" => "V2");
    So i need it to look like that :
    Code:
    "1" => "2", "V2" => "1"
    How is it possible ?

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    41
    You can use :
    Code:
    $fields = array( "ID0" => "V0", "ID1" => "V1");
    //Get the first key
    reset($fields);
    $first_key = key($fields);
    $first_value = $fields[$first_key];
    unset($fields[$first_key]);
    
    $fields[$first_key] = $first_value;

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts