Results 1 to 5 of 5

Thread: [RESOLVED] Declaring an empty array of 4 element (without giving any value yet)

  1. #1

    Thread Starter
    Fanatic Member jcavard's Avatar
    Join Date
    Jul 2005
    Location
    Quebec, CANADA
    Posts
    534

    Resolved [RESOLVED] Declaring an empty array of 4 element (without giving any value yet)

    Hi!

    I have an object that has a property array containing 4 elements, but without any value yet. So if I call array[0] I dont want to have an undefined index error...

    is there anything like array{4} or something like that, that would declare
    array[0]
    array[1]
    array[2]
    array[3] ?????????
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    accoustic emo-rock band: a tailormade fable

    Visual Studio 2003 / Framework 1.1

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Declaring an empty array of 4 element (without giving any value yet)

    You could create an array with null values in them
    PHP Code:
    $your_array = array(0,0,0,0);

    $your_array[0] = "some value";
    $your_array[1] = 12.13;
    $your_array[2] = 123456;
    $your_array[3] = 'valuesasd'

  3. #3

    Thread Starter
    Fanatic Member jcavard's Avatar
    Join Date
    Jul 2005
    Location
    Quebec, CANADA
    Posts
    534

    Re: Declaring an empty array of 4 element (without giving any value yet)

    ok thanks, I had found a work around similar to this
    PHP Code:
     array("","","",""); 
    but wanted to make sure i was not missing somehing, thanks john!
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    accoustic emo-rock band: a tailormade fable

    Visual Studio 2003 / Framework 1.1

  4. #4
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Declaring an empty array of 4 element (without giving any value yet)

    Well as PHP is dynamically typed doesnt really matter what type it is.

    Although lately i have been really lazy and just turned off warning in my scripts

  5. #5

    Thread Starter
    Fanatic Member jcavard's Avatar
    Join Date
    Jul 2005
    Location
    Quebec, CANADA
    Posts
    534

    Re: Declaring an empty array of 4 element (without giving any value yet)

    Quote Originally Posted by john tindell
    Well as PHP is dynamically typed doesnt really matter what type it is.

    Although lately i have been really lazy and just turned off warning in my scripts
    hahaha
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    accoustic emo-rock band: a tailormade fable

    Visual Studio 2003 / Framework 1.1

Posting Permissions

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



Click Here to Expand Forum to Full Width