note 114357 added to function.array-map
| From: | ian_channing at hotmail dot com | Date: | Wed, 12 Feb 2014 11:10:08 +0000 |
| Subject: | note 114357 added to function.array-map | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198466@lists.php.net to get a copy of this message | ||
I wanted a nice way to convert an array with x values as keys and y values as values e.g. array(x
=> y,...) into x,y co-ordinates e.g. array(array(x,y), ...).
You can do:
<?php
foreach ($waveform as $key => $waveformPoint) {
$coordinates[] = array($key, $waveformPoint);
}
?>
But array_map with a null callback gives you a nicer way:
<?php
$coordinates = array_map(null, array_keys($waveform), array_values($waveform));
?>
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/function.array-map.php
Edit -- https://master.php.net/note/edit/114357
Del: integrated -- https://master.php.net/note/delete/114357/integrated
Del: useless -- https://master.php.net/note/delete/114357/useless
Del: bad code -- https://master.php.net/note/delete/114357/bad+code
Del: spam -- https://master.php.net/note/delete/114357/spam
Del: non-english -- https://master.php.net/note/delete/114357/non-english
Del: in docs -- https://master.php.net/note/delete/114357/in+docs
Del: other reasons-- https://master.php.net/note/delete/114357
Reject -- https://master.php.net/note/reject/114357
Search -- https://master.php.net/manage/user-notes.php