php 关联数组 索引数组_在PHP中创建关联数组

php 关联数组 索引数组

In an associative array, we can specify the values with the keys. Then, following two things are required to create an associative array: 1) key, and 2) value

关联数组中 ,我们可以使用键指定值。 然后,需要执行以下两项操作来创建关联数组:1) key和2) value

key can be used as an index to access the value from the array.

键可以用作从数组访问值的索引。

Note: To create an associative or other types of array, we use array() function.

注意:要创建关联数组或其他类型的数组,请使用array()函数

Syntax:

句法:

    array(key1=>value1, key2=>value2, key3=>value3, ...);

Example:

例:

In this example, we are creating an associative array, printing the values: 1) Using keys, and 2) Printing complete array with keys & values

在此示例中,我们将创建一个关联数组,打印值:1)使用键,以及2)打印包含键和值的完整数组

<?php
	//creating student array with keys & values
	$std = array('id' => "101", 'name' => "Amit", 'course' => "B.Tech");

	//printing elemenets
	print ("std elements...\n");
	print ("Id = " . $std['id'] . " Name = " . $std['name'] . " Course = " . $std['course']);
	
	//printing array using for each loop
	
	//printing complete array
	print ("std...\n");
	print_r($std);
?>

Output

输出量

std elements...
Id = 101 Name = Amit Course = B.Techstd...
Array
(
    [id] => 101
    [name] => Amit
    [course] => B.Tech
)


翻译自: https://www.includehelp.com/php/create-an-associative-array.aspx

php 关联数组 索引数组

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值