Results 1 to 2 of 2

Thread: array variable

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    India
    Posts
    117

    array variable

    sir
    i am a newbie in php. how can i put this array in for loop to generate numbers 1, 2, 3, 4.
    now i want to declare like this. but if i have 100 numbers it is very diffcult. please tell me

    how can i use variable in the place of 1, 2, 3, 4, 5?


    $days = array(
    1=>array('testing','linked-day'),
    2=>array('testing','linked-day'),
    3=>array('testing','linked-day'),
    4=>array('testing','linked-day'),
    5=>array('testing','linked-day'),
    );

    ram

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: array variable

    If you omit the key when creating an array then the default zero-based numerical indices are used.

    PHP Code:
    $days = array(
      array(
    'testing''linked-day'),
      array(
    'testing''linked-day'),
      array(
    'testing''linked-day'),
      array(
    'testing''linked-day')
      
    # etc.
    ); 
    1-based arrays are unnecessarily confusing. Either zero-based numerical indices or alphanumeric keys should be used (as a matter of fact, if you specify a string key for each item, you can still access them using zero-based indices).

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