treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Perform Function on Each Item of an Array

Last updated on:

array_map() takes two arguments. The first argument is the function to perform on the second argument (which is an array). Returns a new array.

$original = array('<p>Paragraph</p>', '<strong>Bold</strong>');
$new = array_map('strip_tags', $original);

// $new is now array('Paragraph', 'Bold');
View Comments

Comments

  1. Permalink to comment#

    Nice one. Didn’t know about this function yet. Normally I would do a foreach loop.

Leave a Comment

Use markdown or basic HTML and be nice.