•

Check out our Community Blogs

Register and join over 40,000 other developers!

### Recent Blog Entries

• phi

I love this community !

# Why Associative Array Creation Has "=>" And Numerical Array Not ?

associative array numerical

This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

### #1 uniqueideaman

uniqueideaman

CC Resident

• 59 posts

Posted 21 May 2017 - 04:25 AM

Associative Array

```<html>
<body>

<?php
/* First method to associate create array. */
[b]         \$salaries = array("mohammad" => 2000, "qadir" => 1000, "zara" => 500);[/b]

echo "Salary of zara is ".  \$salaries['zara']. "<br />";

/* Second method to create array. */
\$salaries['zara'] = "low";

echo "Salary of zara is ".  \$salaries['zara']. "<br />";
?>

</body>
</html>
```

Numerical Array

```
<?php
/* First method to create array. */
\$numbers = array( one, two, three, four, five);

foreach( \$numbers as \$value ) {
echo "Value is \$value <br />";
}

/* Second method to create array. */
\$numbers[0] = "one";
\$numbers[1] = "two";
\$numbers[2] = "three";
\$numbers[3] = "four";
\$numbers[4] = "five";

foreach( \$numbers as \$value ) {
echo "Value is \$value <br />";
}
?>

</body>
</html>

```

Look at both code's bold parts on how each different type of arrays create an array.

The Associative Array:
/* First method to associate create array. */

The Numerical Array:
/* First method to create array. */
\$numbers = array( 1, 2, 3, 4, 5);

Why one uses "=>" and one not ? Are they not both procedural style ?
Look:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download