note 114357 deleted from function.array-map by cmb
| From: | cmb@php.net | Date: | Sun, 25 Aug 2019 09:07:06 +0000 |
| Subject: | note 114357 deleted from function.array-map by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211997@lists.php.net to get a copy of this message | ||
Note Submitter: ian_channing at hotmail dot com
----
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));
?>