Php questions

Discussion in 'PHP' started by zoniac, Jul 17, 2012.

  1. #1
    How do I remove an element from an array without changing the index values for the rest of the array?





    Regards,
    Zoniac Team,
    Recruiting and Staffing Solution
    zoniac.com
     
    zoniac, Jul 17, 2012 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    unset? then it doesn't alter the index
     
    EricBruggema, Jul 17, 2012 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    As stated above, using print_r:

    $array = array(1, 5, 8, 9, 0);

    Array
    (
    [0] => 1
    [1] => 5
    [2] => 8
    [3] => 9
    [4] => 0
    )

    unset($array[3]);

    Array
    (
    [0] => 1
    [1] => 5
    [2] => 8
    [4] => 0
    )
     
    jestep, Jul 18, 2012 IP