PHP

PHP Menu

PHP

array_walk() Function - Definition, Syntax, Parameters, Examples

Definition

The array_walk() apply a user-defined function to every element of an array.

Syntax

array_walk(array, callback, userdata)

Parameters

Parameter Description
array Required. Specifies the array to work on.
callback Required. Specifies the name of the user-defined callback function. The callback function typically takes on two parameters — the array value being the first, and the key/index second.
userdata Optional. Specifies a parameter to the user-defined callback function. It will be passed as the third parameter to the callback function.

Example

<?php
function myFunction($value, $key) { echo "Name: $key - " . "Age: $value" . "<br>"; }
$ages = array("Mark" => 22, "Jeff" => 32, "Mike" => 28); array_walk($ages, "myFunction");

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods