Declaring array in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • x1y1z1
    New Member
    • May 2007
    • 1

    Declaring array in php

    hi
    how to declare this c array(eg:int var[10]))in php.
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, x1y1z1. Welcome to TSDN!

    Originally posted by x1y1z1
    how to declare this c array(eg:int var[10]))in php.
    Hm. Where to begin on this one?

    PHP variables are significantly different from C variables. C variables are statically-typed (e.g., int myVar can only hold int values, etc.).

    On the other hand, PHP values are dynamically-typed. So you could do this without causing any problems:
    [code=php]
    $myVar = 5;
    $myVar = 'Hi!';
    [/code]

    Having said that, to declare an array in PHP, you'd just use the array keyword:

    [code=php]
    $myVar = array(
    'key' => 'value'
    );
    [/code]

    The array can have as many or as few elements as you want. You don't have to specify this when you create the array.

    For more information, check out the PHP Manual:

    Comment

    Working...