home HOME

PHP Basic
PHP HOME
PHP Intro
PHP Install
PHP Syntax
PHP Variables
PHP String
PHP Operators
PHP If...Else
PHP Switch
PHP Arrays
PHP Looping
PHP Functions
PHP Forms
PHP $_GET
PHP $_POST

PHP Advanced
PHP Date
PHP Include
PHP File
PHP File Upload
PHP Cookies
PHP Sessions
PHP E-mail
PHP Secure E-mail
PHP Error
PHP Exception
PHP Filter

PHP Database
MySQL Introduction
MySQL Connect
MySQL Create
MySQL Insert
MySQL Select
MySQL Where
MySQL Order By
MySQL Update
MySQL Delete
PHP ODBC

PHP XML
XML Expat Parser
XML DOM
XML SimpleXML

PHP and AJAX
AJAX Introduction
XMLHttpRequest
AJAX Suggest
AJAX XML
AJAX Database
AJAX responseXML
AJAX Live Search
AJAX RSS Reader
AJAX Poll

PHP Reference
PHP Array
PHP Calendar
PHP Date
PHP Directory
PHP Error
PHP Filesystem
PHP Filter
PHP FTP
PHP HTTP
PHP Libxml
PHP Mail
PHP Math
PHP Misc
PHP MySQL
PHP SimpleXML
PHP String
PHP XML
PHP Zip

PHP Quiz
PHP Quiz

Selected Reading
Web Statistics
Web Glossary
Web Hosting
Web Quality

W3Schools Forum

Helping W3Schools

pixels

PHP array_walk() Function


PHP Array Reference Complete PHP Array Reference

Definition and Usage

The array_walk() function runs each array element in a user-made function. The array's keys and values are parameters in the function. Returns True or False

Syntax

array_walk(array,function,parameter...)

Parameter Description
array Required. Specifying an array
function Required. The name of the user-made function
parameter Optional. Specifies a parameter to the user-made function


Tips and Notes

Tip: You can assign one parameter to the function, or as many as you like.

Note: You can change an array element's value in the user-made function by specifying the first parameter as a reference: &$value. (See example 3)


Example 1

<?php
function myfunction($value,$key) 
{
echo "The key $key has the value $value<br />";
}
$a=array("a"=>"Cat","b"=>"Dog","c"=>"Horse");
array_walk($a,"myfunction");
?>

The output of the code above will be:

The key a has the value Cat
The key b has the value Dog
The key c has the value Horse


Example 2

With a parameter:

<?php
function myfunction($value,$key,$p) 
{
echo "$key $p $value<br />";
}
$a=array("a"=>"Cat","b"=>"Dog","c"=>"Horse");
array_walk($a,"myfunction","has the value");
?>

The output of the code above will be:

a has the value Cat
b has the value Dog
c has the value Horse


Example 3

Change an array element's value. (Notice the &$value)

<?php
function myfunction(&$value,$key) 
{
$value="Bird;
}
$a=array("a"=>"Cat","b"=>"Dog","c"=>"Horse");
array_walk($a,"myfunction");
print_r($a);
?>

The output of the code above will be:

Array ( [a] => Bird [b] => Bird [c] => Bird ) 


PHP Array Reference Complete PHP Array Reference


Add automated outbound phone calls to your application!

   Enhance your project with this inexpensive reliable Web Service. Phone calls can be sent as pre-recorded sound files, text to speech, or by using a combination of both. You can also change call flow based on interaction.

Phone Notify! is being utilized for fraud prevention, emergency notification calls, courtesy calls, automated telemarketing calls, voice broadcasts, automated dialers, appointment reminders and more.

50 FREE phone calls for W3School users >


Jump to: Top of Page or HOME or Printer Friendly Printer friendly page

W3Schools provides material for training only. We do not warrant the correctness of its contents. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 1999-2007 by Refsnes Data. All Rights Reserved.

Validate Validate W3C-WAI level A conformance icon W3Schools was converted to XHTML in December 1999
SITE SEARCH
 
About W3Schools
W3Schools Forum
Shopping Cart
ASP.NET
Shopping Cart
WEB HOSTING
$15 Domain Name
Registration
Save $20 / year!
UK Domain Names
UK Web Hosting

Alojamiento Web
Buy UK Domain Names
Register Domain Names
Cheap Domain Names
Cheap Web Hosting
Best Web Hosting
Domain Name Registration
PHP MySQL Hosting
Top 10 Web Hosting
Web Hosting Providers
Web Hosting Company
WEB BUILDING
Convert HTML to XML
Website Templates
Flash Templates
Website Builder
Internet Business Opportunity
Custom Programming
Web Design Forum
Programming Forum
FREE Trial or Demo
Web Content Manager
Forms,Web Alerts,RSS
Free Thumbnail Maker
Free Video Tutorials
HTML Exam
SHOPPING
UK Wholesalers
UK Wholesale
Online Casinos
Batteries
ONLINE DEGREE
Advance Your Career
with Drexel University
Bachelor's & Master's
Tech Degrees ONLINE
US Web Design Schools
YELLOW PAGES
www.nettkatalogen.no
www.gulex.dk
www.gulex.se
www.gelbex.de

pixels