Voting

: min(four, six)?
(Example: nine)

The Note You're Voting On

directrix1 at gmail dot com
9 years ago
So, if you were wondering how to use this where key and value are passed in to the function. I've had success with the following (this example generates formatted html attributes from an associative array of attribute => value pairs):

<?php

// Attribute List
$attribs = [
'name' => 'first_name',
'value' => 'Edward'
];

// Attribute string formatted for use inside HTML element
$formatted_attribs = array_reduce(
array_keys($attribs), // We pass in the array_keys instead of the array here
function ($carry, $key) use ($attribs) { // ... then we 'use' the actual array here
return $carry . ' ' . $key . '="' . htmlspecialchars( $attribs[$key] ) . '"';
},
''
);

echo
$formatted_attribs;

?>

This will output:
name="first_name" value="Edward"

<< Back to user notes page

To Top