<?php
$geos = array(
array(
"type" => "STATE",
"state" => "TX"
),
array(
"type" => "STATE",
"state" => "MI"
),
array(
"type" => "STATE",
"state" => "CA"
)
);
$geos = array(
array(
"type" => "DMA",
"dma" => 635
),
array(
"type" => "DMA",
"dma" => 618
),
array(
"type" => "DMA",
"dma" => 803
)
);
$geos = array(
array(
"type"=> "CITY",
"state"=> "TX",
"city"=> "Austin"
),
array(
"type"=> "CITY",
"state"=> "MI",
"city"=> "East Lansing"
),
array(
"type"=> "CITY",
"state"=> "TX",
"city"=> "Houston"
)
);
// figure out type
$geoValues = array();
$geoTypeUppercase = count($geos) ? $geos[0]['type'] : null;
if ($geoTypeUppercase === 'CITY') {
$geoValues = array_map(function($geo) {
return $geo['city'] . ', ' . $geo['state'];
}, $geos);
}
else if (in_array($geoTypeUppercase, array('STATE', 'DMA'))) {
$geoValues = array_map(function($geo) use ($geoTypeUppercase) {
return $geo[strtolower($geoTypeUppercase)];
}, $geos);
}
if (count($geoValues)) {
print_r($geoTypeUppercase);
$geoType = 'geoType' . ucword($geoTypeUppercase);
print_r($geoType);
print_r($geoValues);
}
preferences:
51.79 ms | 402 KiB | 5 Q