PHP array help needed

Discussion in 'PHP' started by kapeel_sable, Sep 18, 2009.

  1. #1
    Hello guys,

    I want to make an array in such a way that if i have a specific value , assume 3 , then my array should be

    Array
    (
    [1] => 1
    [2] => 2
    [3] => 3
    )

    But '3' will always change as it will be a variable.
     
    kapeel_sable, Sep 18, 2009 IP
  2. skript

    skript Active Member

    Messages:
    81
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    93
    #2
    So for '5' you will have:
    Array
    (
    [1] => 1
    [2] => 2
    [3] => 3
    [4] => 4
    [5] => 5
    )

    If this is the case, this will do it:
    $a = array();
    for($i=1; $i<=$variable; $i++)
        $a[$i] = $i;
    PHP:
     
    skript, Sep 18, 2009 IP
  3. kapeel_sable

    kapeel_sable Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    worked like a charm.
    please pm me your yahoo/gmail id.
     
    kapeel_sable, Sep 18, 2009 IP