mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-08-22 17:02:58 +02:00
Update code example in PHP roadmap (#8973)
This commit is contained in:
committed by
GitHub
parent
4037e3bb31
commit
bc4e29521b
@@ -3,11 +3,11 @@
|
||||
Associative arrays in PHP are a type of array that uses named keys instead of numeric ones. This provides a more human-readable way to store data where each value can be accessed by its corresponding string key. An example of an associative array could be storing names as keys and their corresponding ages as values. Here's a brief example:
|
||||
|
||||
```php
|
||||
$ages = array(
|
||||
$ages = [
|
||||
"Peter" => 35,
|
||||
"John" => 42,
|
||||
"Mary" => 27
|
||||
);
|
||||
];
|
||||
```
|
||||
|
||||
In this case, to find out John's age, you would simply use `echo $ages['John']` where 'John' is the key. Associative arrays are also easy to loop through using the `foreach` construct.
|
||||
|
@@ -5,7 +5,7 @@ Indexed arrays in PHP store values that are accessed through numerical indexes,
|
||||
Here's an Example:
|
||||
|
||||
```php
|
||||
$books = array("The Great Gatsby", "Moby Dick", "To Kill a Mockingbird");
|
||||
$books = ["The Great Gatsby", "Moby Dick", "To Kill a Mockingbird"];
|
||||
echo $books[0]; //Outputs "The Great Gatsby"
|
||||
```
|
||||
|
||||
|
@@ -5,11 +5,11 @@ Multi-dimensional arrays in PHP are a type of array that contains one or more ar
|
||||
Here's an example:
|
||||
|
||||
```php
|
||||
$users = array(
|
||||
array("John", "john@example.com", "john123"),
|
||||
array("Jane", "jane@example.com", "jane123"),
|
||||
array("Doe", "doe@example.com", "doe123")
|
||||
);
|
||||
$users = [
|
||||
["John", "john@example.com", "john123"],
|
||||
["Jane", "jane@example.com", "jane123"],
|
||||
["Doe", "doe@example.com", "doe123"]
|
||||
];
|
||||
```
|
||||
|
||||
Visit the following resources to learn more:
|
||||
|
Reference in New Issue
Block a user