php put教程,PHP Ds\Map put()用法及代码示例

Ds \ Map::put()函数是PHP中的内置函数,用于将键与值相关联。

用法:

void public Ds\Map::put( $key, $value )

参数:该函数接受上述和以下描述的两个参数:

$key:它用于按住键来关联值。

$value:它用于保存键的值。

返回值:该函数不返回任何值。

以下示例程序旨在说明PHP中的Ds \ Map::put()函数:

程序1:

// Declare a new map

$map = new \Ds\Map();

$map->put("a", "Geeks");

$map->put("b", "for");

$map->put("c", "Geeks");

// Display output

print_r($map);

// Declare a new map

$map = new \Ds\Map();

$map->put("a", "Computer");

$map->put("b", "Science");

$map->put("c", "Portal");

// Display output

print_r($map);

?>

输出:

Ds\Map Object

(

[0] => Ds\Pair Object

(

[key] => a

[value] => Geeks

)

[1] => Ds\Pair Object

(

[key] => b

[value] => for

)

[2] => Ds\Pair Object

(

[key] => c

[value] => Geeks

)

)

Ds\Map Object

(

[0] => Ds\Pair Object

(

[key] => a

[value] => Computer

)

[1] => Ds\Pair Object

(

[key] => b

[value] => Science

)

[2] => Ds\Pair Object

(

[key] => c

[value] => Portal

)

)

程序2:

// Declare a new map

$map = new \Ds\Map();

$map->put("Geeks1", "computer");

$map->put("Geeks2", "science");

$map->put("Geeks3", 5);

$map->put("Geeks3", 20);

// Display result

var_dump($map);

?>

输出:

object(Ds\Map)#1 (3) {

[0]=>

object(Ds\Pair)#2 (2) {

["key"]=>

string(6) "Geeks1"

["value"]=>

string(8) "computer"

}

[1]=>

object(Ds\Pair)#3 (2) {

["key"]=>

string(6) "Geeks2"

["value"]=>

string(7) "science"

}

[2]=>

object(Ds\Pair)#4 (2) {

["key"]=>

string(6) "Geeks3"

["value"]=>

int(20)

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值