PHP array_walk() 函数

2025 年 1 月 6 日 | 阅读 2 分钟

array_walk() 函数是 PHP 的内置函数。它用于将用户定义的函数应用于数组中的每个元素。此函数于 4.0 版本引入。

语法

参数

参数描述必需
数组输入的数组。必需
用户函数用户定义函数的名称。必需
用户数据如果提供了此参数,它将作为第三个参数传递给用户函数。可选

返回值

array_walk() 函数成功时返回 true,失败时返回 false。

示例 1

输出

The key a has the value youtube
The key b has the value google
The key c has the value whatsapp

示例 2

输出

Javatpoint tutorial1 has php
Javatpoint tutorial2 has java 
Javatpoint tutorial3 has python

示例 3

输出

cricket and sachin have been paired together.
hockey and sandeep have been paired together.

示例 4

输出

The key a has the value aajtak.
The key b has the value zee news.
The key c has the value ndtv.

下一主题PHP 字符串