PHP/Data Structure/array combine
Версия от 13:37, 26 мая 2010; (обсуждение)
array_combine
<source lang="html4strict">
<?php $abbreviations = array("AL","AK","AZ","AR"); $states = array("Alabama","Alaska","Arizona","Arkansas"); $stateMap = array_combine($abbreviations,$states); print_r($stateMap); ?>
</source>
Combining Arrays
<source lang="html4strict">
<?php $colors = array("red", "yellow", "green"); $flavors = array("apple", "banana", "lime"); $tastes = array("sweet", "sour"); $prices = array(); $name = "lemon"; $arrays = array("name" => $name, "prices" => $prices, "flavors" => $flavors); foreach($arrays as $key => $value) {
if($fruits = @array_combine($colors, $value))printf("
%s\n", var_export($fruits, TRUE));
elseprintf("
Couldn"t combine \$colors and \$%s.
", $key);} ?>
</source>