Contenido del Curso
Introduction to PHP
Introduction to PHP
Associative Arrays
Associative arrays in PHP are arrays that provide a mapping between keys and values. They are used to store data in the form of key-value pairs, where each key is unique and associated with a specific value.
Creation Syntax
Associative arrays are created using the key operator =>
to establish the relationship between the key and the value. For example:
main
$user = [ "name" => "John", "age" => 30, "city" => "New York" ];
As a result, this code creates an associative array $user
with three keys: "name"
, "age"
, and "city"
, and their corresponding values: "John"
, 30
, and "New York"
. You can access these values using their respective keys:
main
<?php $user = array( "name" => "John", "age" => 30, "city" => "New York" ); echo $user["name"]; // Output "John" ?>
Swipe to show code editor
Fill in the blanks in the code to create an associative array $person
with three key-value pairs (e.g., 'name' => 'John'
, 'age' => 25
, 'profession' => 'Engineer'
). Then, access the value by the key 'name'
and print it to the screen.
¡Gracias por tus comentarios!
Associative Arrays
Associative arrays in PHP are arrays that provide a mapping between keys and values. They are used to store data in the form of key-value pairs, where each key is unique and associated with a specific value.
Creation Syntax
Associative arrays are created using the key operator =>
to establish the relationship between the key and the value. For example:
main
$user = [ "name" => "John", "age" => 30, "city" => "New York" ];
As a result, this code creates an associative array $user
with three keys: "name"
, "age"
, and "city"
, and their corresponding values: "John"
, 30
, and "New York"
. You can access these values using their respective keys:
main
<?php $user = array( "name" => "John", "age" => 30, "city" => "New York" ); echo $user["name"]; // Output "John" ?>
Swipe to show code editor
Fill in the blanks in the code to create an associative array $person
with three key-value pairs (e.g., 'name' => 'John'
, 'age' => 25
, 'profession' => 'Engineer'
). Then, access the value by the key 'name'
and print it to the screen.
¡Gracias por tus comentarios!
Associative Arrays
Associative arrays in PHP are arrays that provide a mapping between keys and values. They are used to store data in the form of key-value pairs, where each key is unique and associated with a specific value.
Creation Syntax
Associative arrays are created using the key operator =>
to establish the relationship between the key and the value. For example:
main
$user = [ "name" => "John", "age" => 30, "city" => "New York" ];
As a result, this code creates an associative array $user
with three keys: "name"
, "age"
, and "city"
, and their corresponding values: "John"
, 30
, and "New York"
. You can access these values using their respective keys:
main
<?php $user = array( "name" => "John", "age" => 30, "city" => "New York" ); echo $user["name"]; // Output "John" ?>
Swipe to show code editor
Fill in the blanks in the code to create an associative array $person
with three key-value pairs (e.g., 'name' => 'John'
, 'age' => 25
, 'profession' => 'Engineer'
). Then, access the value by the key 'name'
and print it to the screen.
¡Gracias por tus comentarios!
Associative arrays in PHP are arrays that provide a mapping between keys and values. They are used to store data in the form of key-value pairs, where each key is unique and associated with a specific value.
Creation Syntax
Associative arrays are created using the key operator =>
to establish the relationship between the key and the value. For example:
main
$user = [ "name" => "John", "age" => 30, "city" => "New York" ];
As a result, this code creates an associative array $user
with three keys: "name"
, "age"
, and "city"
, and their corresponding values: "John"
, 30
, and "New York"
. You can access these values using their respective keys:
main
<?php $user = array( "name" => "John", "age" => 30, "city" => "New York" ); echo $user["name"]; // Output "John" ?>
Swipe to show code editor
Fill in the blanks in the code to create an associative array $person
with three key-value pairs (e.g., 'name' => 'John'
, 'age' => 25
, 'profession' => 'Engineer'
). Then, access the value by the key 'name'
and print it to the screen.