How to append this array as it is in php - php

I need to append this array in php script
.Kindly help to do it perfectly .I tried multiple solution but none resulted to correct solution.
Array(
[Donn] => 0
[Lamo] => 0
[Otis] => 0
[Stev] => 0
[Matt] => 0
[Samm] => 0
[Andr] => 0
[Jerr] => 0
[Simm] => 0
[Steph] => 0
[Fredd] => 0
[Willi] => 0
)
to the following array
Array(
[Don] => Array
(
[Ab] => 1
[Ang] => 1
[Ant] => 2
[Bo] => 1
[Ch] => 1
[Chri] => 2
[Chri] => 4
[Deau] => 1
[Der] => 1
[Sylveste] => 1
)
[Lam] => Array
(
[Ab] => 2
[Ch] => 22
[Dona] => 1
[Irw] => 1
[Kou] => 1
[Llo] => 1
[Ro] => 1
[Shumy] => 1
)
[Oti] => Array
(
[Ab] => 1
[Arla] => 1
[Kour] => 1
[Osh] => 1
[Roy ] => 1
[Tim] => 1
[War] => 1
//add the given array here
))
So that the result is
Array([Don] => Array
(
[Ab] => 1
[Ang] => 1
[Ant] => 2
[Bo] => 1
[Ch] => 1
[Chri] => 2
[Chri] => 4
[Deau] => 1
[Der] => 1
[Sylveste] => 1
)
[Lam] => Array
(
[Ab] => 2
[Ch] => 22
[Dona] => 1
[Irw] => 1
[Kou] => 1
[Llo] => 1
[Ro] => 1
[Shumy] => 1
)
[Oti] => Array
(
[Ab] => 1
[Arla] => 1
[Kour] => 1
[Osh] => 1
[Roy ] => 1
[Tim] => 1
[War] => 1
[Donn] => 0
[Lamo] => 0
[Otis] => 0
[Stev] => 0
[Matt] => 0
[Samm] => 0
[Andr] => 0
[Jerr] => 0
[Simm] => 0
[Steph] => 0
[Fredd] => 0
[Willi] => 0
//added here
))
Please use least loops as much as possible.So as to get time feasible solution.Use php array function if possible.

Use foreach to add into the oti index:
<?php
$firstArr = Array(
"Don" => Array
(
"Ab" => 1,
"Ang" => 1,
"Ant" => 2,
"Bo" => 1,
"Ch" => 1,
"Chri" => 2,
"Chri" => 4,
"Deau" => 1,
"Der" => 1,
"Sylveste" => 1,
),
"Lam" => Array
(
"Ab" => 2,
"Ch" => 22,
"Dona" => 1,
"Irw" => 1,
"Kou" => 1,
"Llo" => 1,
"Ro" => 1,
"Shumy" => 1,
),
"Oti" => Array
(
"Ab" => 1,
"Arla" => 1,
"Kour" => 1,
"Osh" => 1,
"Roy " => 1,
"Tim" => 1,
"War" => 1,
//add the given array here
));
$secondArr = Array(
"Donn" => 0,
"Lamo" => 0,
"Otis" => 0,
"Stev" => 0,
"Matt" => 0,
"Samm" => 0,
"Andr" => 0,
"Jerr" => 0,
"Simm" => 0,
"Steph" => 0,
"Fredd" => 0,
"Willi" => 0,
);
foreach ($secondArr as $key => $value) {
$firstArr["Oti"][$key] = $value;
}
print_r($firstArr);
Demo
You can also use array_merge as #Mark Baker said in comments:
$firstArr["Oti"] = array_merge($firstArr["Oti"], $secondArr);

This should solve it, you use the array_merge function to merge the 2 arrays :)
$secondArray['Oti'] = array_merge($secondArray['Oti'], $firstArray);

Related

Sorting an array of array in PHP

Request your help on sorting an array of array in PHP as below, tried all these function ksort, usort, arsort, krsort nothing seem to be working, any help would be much appreciated.
Original Array
Array
(
[serv1-DB] => Array
(
[2019-11-22] => 0
[2019-11-23] => 0
[2019-11-24] => 0
[2019-11-25] => 1
[2019-11-26] => 3
[2019-11-27] => 3
[2019-11-28] => 3
[2019-11-29] => 3
)
[ser2-DB] => Array
(
[2019-11-25] => 0
[2019-11-24] => 0
[2019-11-22] => 0
[2019-11-23] => 0
[2019-11-26] => 3
[2019-11-27] => 3
[2019-11-28] => 3
[2019-11-29] => 3
)
Output Required
Array
(
[serv1-DB] => Array
(
[2019-11-29] => 3
[2019-11-28] => 3
[2019-11-27] => 3
[2019-11-26] => 3
[2019-11-25] => 1
[2019-11-24] => 0
[2019-11-23] => 0
[2019-11-22] => 0
)
[ser2-DB] => Array
(
[2019-11-29] => 3
[2019-11-28] => 3
[2019-11-27] => 3
[2019-11-26] => 3
[2019-11-25] => 0
[2019-11-24] => 0
[2019-11-23] => 0
[2019-11-22] => 0
)
You want to sort the sub arrays, so you need to loop over each of them (in write mode) and sort the keys in reverse order using krsort:
foreach ($array as &$subArray) {
krsort($subArray);
}
Demo: https://3v4l.org/g8pBu
You have to sort reversely on the arrays like this:
// The arrays
$arrays = array(
"serv1-DB" => array(
"2019-11-22" => 0,
"2019-11-23" => 0,
"2019-11-24" => 0,
"2019-11-25" => 1,
"2019-11-26" => 3,
"2019-11-27" => 3,
"2019-11-28" => 3,
"2019-11-29" => 3
),
"ser2-DB" => array(
"2019-11-25" => 0,
"2019-11-24" => 0,
"2019-11-22" => 0,
"2019-11-23" => 0,
"2019-11-26" => 3,
"2019-11-27" => 3,
"2019-11-28" => 3,
"2019-11-29" => 3
)
);
// The sorting part
foreach($arrays AS $k => $array) {
krsort($array);
$arrays[$k] = $array;
}

how to display multidimensional array without knowing depth?

I have one large multidimensional array(I dnt the depth of array) and I want to display it in tabular form . this is one array from my array
[Kai Roger Tester] => Array
(
[Ikke navngitt] => Array
(
[status] => Array
(
[documents_green] => 0
[documents_yellow] => 0
[documents_red] => 3
[waiting_approval_documents] => 1
[waiting_verfication_documents] => 0
[under_construction_documents] => 3
)
)
[Finnfjord] => Array
(
[NVD test] => Array
(
[status] => Array
(
[documents_green] => 0
[documents_yellow] => 0
[documents_red] => 1
[waiting_approval_documents] => 0
[waiting_verfication_documents] => 0
[under_construction_documents] => 5
)
)
[status] => Array
(
[documents_green] => 0
[documents_yellow] => 0
[documents_red] => 0
[waiting_approval_documents] => 0
[waiting_verfication_documents] => 0
[under_construction_documents] => 2
)
)
[Endringslogg] => Array
(
[status] => Array
(
[documents_green] => 0
[documents_yellow] => 0
[documents_red] => 0
[waiting_approval_documents] => 0
[waiting_verfication_documents] => 0
[under_construction_documents] => 1
)
)
[Laste opp doc] => Array
(
[status] => Array
(
[documents_green] => 0
[documents_yellow] => 0
[documents_red] => 1
[waiting_approval_documents] => 0
[waiting_verfication_documents] => 0
[under_construction_documents] => 1
)
)
[status] => Array
(
[documents_green] => 1
[documents_yellow] => 0
[documents_red] => 6
[waiting_approval_documents] => 3
[waiting_verfication_documents] => 4
[under_construction_documents] => 13
)
)
[Prosess 1] => Array
(
[AF Decom] => Array
(
[status] => Array
(
[documents_green] => 1
[documents_yellow] => 0
[documents_red] => 0
[waiting_approval_documents] => 0
[waiting_verfication_documents] => 0
[under_construction_documents] => 3
)
)
[status] => Array
(
[documents_green] => 7
[documents_yellow] => 0
[documents_red] => 2
[waiting_approval_documents] => 0
[waiting_verfication_documents] => 0
[under_construction_documents] => 11
)
)
Folder Name green yellow red
Kai Roger Tester 1 0 6
Ikke navngitt' 0 0 3
Finnfjord 0 0 0
NVD test 0 0 1
Process1 1 1 0
I tired with below method
public static function getfoldertable($array, $prefix = '') {
$body_start = "<tbody>";
if (count($array) > 0 && is_array($array)) {
$i = 0;
foreach ($array as $key => $row) {
$body_start.='<tr>
<td>'.$i.'</td>
<td>'.$key.'</td>
<td>'.$row['status']['documents_green'].'</td>
<td>'.$row['status']['documents_yellow'].'</td>
<td>'.$row['status']['documents_red'].'</td>
</tr>';
$body_start.= self::getfoldertable($row, $prefix . '-');
$i++;
}
$body_start.="</tbody>";
}
//echo $body_start; die;
return $body_start;
}
Can anyone help me how can i display this?
Thanks in advance
Here is a function you could use for generating that output:
function getTreeHTML($tree, $level = 0) {
$html = "";
$indent = str_repeat(" ", $level * 2);
foreach ($tree as $key => $value) {
if ($key == "status") continue;
$html .= "
<tr><td>$indent$key</td>
<td>{$value['status']['documents_green']}</td>
<td>{$value['status']['documents_yellow']}</td>
<td>{$value['status']['documents_red']}</td>
</tr>" . getTreeHTML($value, $level+1);
}
return $html;
}
If the input data is defined like this:
$input = array (
'Kai Roger Tester' =>
array (
'Ikke navngitt' =>
array (
'status' =>
array (
'documents_green' => 0,
'documents_yellow' => 0,
'documents_red' => 3,
'waiting_approval_documents' => 1,
'waiting_verfication_documents' => 0,
'under_construction_documents' => 3,
),
),
'Finnfjord' =>
array (
'NVD test' =>
array (
'status' =>
array (
'documents_green' => 0,
'documents_yellow' => 0,
'documents_red' => 1,
'waiting_approval_documents' => 0,
'waiting_verfication_documents' => 0,
'under_construction_documents' => 5,
),
),
'status' =>
array (
'documents_green' => 0,
'documents_yellow' => 0,
'documents_red' => 0,
'waiting_approval_documents' => 0,
'waiting_verfication_documents' => 0,
'under_construction_documents' => 2,
),
),
'Endringslogg' =>
array (
'status' =>
array (
'documents_green' => 0,
'documents_yellow' => 0,
'documents_red' => 0,
'waiting_approval_documents' => 0,
'waiting_verfication_documents' => 0,
'under_construction_documents' => 1,
),
),
'Laste opp doc' =>
array (
'status' =>
array (
'documents_green' => 0,
'documents_yellow' => 0,
'documents_red' => 1,
'waiting_approval_documents' => 0,
'waiting_verfication_documents' => 0,
'under_construction_documents' => 1,
),
),
'status' =>
array (
'documents_green' => 1,
'documents_yellow' => 0,
'documents_red' => 6,
'waiting_approval_documents' => 3,
'waiting_verfication_documents' => 4,
'under_construction_documents' => 13,
),
),
'Prosess 1' =>
array (
'AF Decom' =>
array (
'status' =>
array (
'documents_green' => 1,
'documents_yellow' => 0,
'documents_red' => 0,
'waiting_approval_documents' => 0,
'waiting_verfication_documents' => 0,
'under_construction_documents' => 3,
),
),
'status' =>
array (
'documents_green' => 7,
'documents_yellow' => 0,
'documents_red' => 2,
'waiting_approval_documents' => 0,
'waiting_verfication_documents' => 0,
'under_construction_documents' => 11,
),
),
);
...and you would call that function like this:
$html = getTreeHTML($input);
...embedding that HTML result as follows in a table:
<table border=1>
<tr><th>Folder Name</th><th>green</th><th>yellow</th><th>red</th></tr>
<?=$html?>
</table>
...then the output would look in a browser like this:
Use RecursiveIterator.
Working code:
$array = array();
$array[0] = array('test' => array('asdf', 'asdf', array('asf', array('asdfads', 'asdf' => array(234,234,234)))));
$iterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator($array),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $key => $item) {
if (is_array($item)) {
echo '<pre>';print_r($item);echo '</pre>';
}
}

Compare multi-dimensional array and return missing keys in array

I have two multi-dimensional associative array ,
first we have
Array
(
[user_authentication] => Array
(
[api_user_id] => xxxxxxxxxxxxxxxxxxxxxxxx
[api_auth_token] => xxxxxxxxxxxxxxxxxxxxxx
)
[campaign_details] => Array
(
[campaign_name] => democampaign
[campaign_category] => appsGames
[campaign_sub_category] => Action
[campaign_type] => cpc
[campaign_start_date] => MM/DD/YYYY
[campaign_end_date] => MM/DD/YYYY
[campaign_start_time] => HH:mm
[campaign_end_time] => HH:mm
)
[campaign_budget_info] => Array
(
[campaign_daily_budget] => 0.2
[campaign_hourly_budget] => 0.3
[campaign_bid] => 0.1
[campaign_budget] => 1
)
[campaign_targetting_info] => Array
(
[campaign_os_type] => Apple
[country_code] => IN,AF,AG
[state_id] => Array
(
[IN] => 1,2,3
[AF] => 4,5,6
[AG] => 7,8,9
)
[carrier] => Array
(
[IN] => Tata,Aircel,RCOM,Vodafone,Airtel,Idea Cellular,Uninor,Dishnet,BSNL
[AF] =>
[AG] =>
)
[isp] =>
[device_targeting] => iphone,ipad
[conversion] =>
)
[campaign_creative_info] => Array
(
[campaign_domain] => abcd.com
[campaign_click_url] => http://url-to-redirect-users-to-after-they-click.com/
[campaign_banner_size] => URL640x1136
[campaign_banner_url] => http://imageurl.com/
[campaign_creative_type] => image
)
[campaign_black_list_white_list_info] => Array
(
[black_list_app_ids] => 5388dceb96c4b54a0844e4cb,5330b3864dab485e6219ff54
[black_list_device_ids] => aaaaaaaa-bbbb-cccc-0000-222222221111,12f93cf2-91ed-4f8f-aae7-a0520bebdd2r
[black_list_ip_addresses] => 123.123.12.123,10.100.100.100
[white_list_app_ids] => 5388dceb96c4b54a0844e4cb,5330b3864dab485e6219ff54
[white_list_device_ids] => aaaaaaaa-bbbb-cccc-0000-222222221111,12f93cf2-91ed-4f8f-aae7-a0520bebdd2r
[white_list_ip_addresses] => 123.123.12.123,10.100.100.100
)
)
and second one is which i have make to compare with
Array
(
[user_authentication] => Array
(
[api_user_id] => 1
[api_auth_token] => 1
)
[campaign_details] => Array
(
[campaign_name] => 1
[campaign_category] => 1
[campaign_sub_category] => 1
[campaign_type] => 1
[campaign_start_date] => 1
[campaign_end_date] => 1
[campaign_start_time] => 1
[campaign_end_time] => 1
)
[campaign_budget_info] => Array
(
[campaign_daily_budget] => 1
[campaign_hourly_budget] => 1
[campaign_bid] => 1
[campaign_budget] => 1
)
[campaign_targetting_info] => Array
(
[campaign_os_type] => 1
[country_code] => 1
[state_id] => Array
(
[IN] => 1
[AF] => 1
[AG] => 1
)
[carrier] => Array
(
[IN] => 1
[AF] => 1
[AG] => 1
)
[isp] => 1
[device_targeting] => 1
[conversion] => 1
)
[campaign_creative_info] => Array
(
[campaign_domain] => 1
[campaign_click_url] => 1
[campaign_banner_size] => 1
[campaign_banner_url] => 1
[campaign_creative_type] => 1
)
[campaign_black_list_white_list_info] => Array
(
[black_list_app_ids] => 1
[black_list_device_ids] => 1
[black_list_ip_addresses] => 1
[white_list_app_ids] => 1
[white_list_device_ids] => 1
[white_list_ip_addresses] => 1
)
)
we have to compare the array and find which key is missing in first array
i have tried this but not working
$comparemodel= array_diff_assoc($array1,$array2);
if($comparemodel==0){
echo "hello";
}
else{
$keys = array_keys($comparemodel);
for ($i = 0; $i < count($keys); $i++) {
$error_message[] = $keys[$i] . " is missing";
}
$model = array();
$errors = array("error_code" => 3042, "error_message" => $error_message);
$message = $error_message;
$status = 0;
$finalarray = array("modal" => $model, "errors" => $errors, "message" => $message, "status" => $status);
echo json_encode($finalarray);
}
its not working with this associative array but its working with simple array. what should i do for this.
thanks
try this code
<?php
$arr1=array("campaign_details" => array
(
"campaign_name" => "democampaign",
"campaign_category" => "appsGames",
"campaign_sub_category" => "Action",
"campaign_type" => "cpc",
"campaign_start_date" => "MM/DD/YYYY",
"campaign_end_date" => "MM/DD/YYYY",
"campaign_start_time" => "HH:mm",
"campaign_end_time" => "HH:mm"
),
"campaign_budget_info" => array
(
"campaign_daily_budget" => 0.2,
"campaign_hourly_budget" => 0.3,
"campaign_bid" => 0.1,
"campaign_budget" => 1,
),
"campaign_targetting_info" => array
(
"campaign_os_type" => "Apple",
"country_code" => "IN,AF,AG",
"state_id" => array
(
"IN" => "1,2,3",
"AF" => "4,5,6",
"AG" => "7,8,9"
),
"carrier" => Array
(
"IN" => "Tata,Aircel,RCOM,Vodafone,Airtel,Idea
Cellular,Uninor,Dishnet,BSNL",
"AF" => "",
"AG" => "",
),
"isp" => "",
"device_targeting" => "iphone,ipad",
"conversion" => "",
),
"campaign_creative_info" => array
(
"campaign_domain" => "abcd.com",
"campaign_click_url" => "http://url-to-redirect-users-to-after-
they-click.com/",
"campaign_banner_size" => "URL640x1136",
"campaign_banner_url" => "http://imageurl.com/",
"campaign_creative_type" => "image",
),
"campaign_black_list_white_list_info" => array
(
"black_list_app_ids" =>
"5388dceb96c4b54a0844e4cb,5330b3864dab485e6219ff54",
"black_list_device_ids" => "aaaaaaaa-bbbb-cccc-
0000-222222221111,12f93cf2-91ed-4f8f-aae7-a0520bebdd2r",
"black_list_ip_addresses" => "123.123.12.123,10.100.100.100",
"white_list_app_ids" =>
"5388dceb96c4b54a0844e4cb,5330b3864dab485e6219ff54",
"white_list_device_ids" => "aaaaaaaa-bbbb-cccc-
0000-222222221111,12f93cf2-91ed-4f8f-aae7-a0520bebdd2r",
"white_list_ip_addresses" => "123.123.12.123,10.100.100.100",
)
);
$arr2=array("campaign_details" =>array
(
"campaign_name" => 1,
"campaign_category" => 1,
"campaign_sub_category" => 1,
"campaign_type" => 1,
"campaign_start_date" => 1,
"campaign_end_date" => 1,
"campaign_start_time" => 1,
"campaign_end_time" => 1
),
"campaign_budget_info" => array
(
"campaign_daily_budget" => 1,
"campaign_hourly_budget" => 1,
"campaign_bid" => 1,
"campaign_budget" => 1,
),
"campaign_targetting_info" => array
(
"campaign_os_type" => 1,
"country_code" => 1,
"state_id" => array
(
"IN" => 1,
"AF" => 1,
"AG" => 1,
),
"carrier" => array
(
"IN" => 1,
"AF" => 1,
"AG" => 1,
),
"isp" => 1,
"device_targeting" => 1,
"conversion" => 1,
),
"campaign_creative_info" =>array
(
"campaign_domain" => 1,
"campaign_click_url" => 1,
"campaign_banner_size" => 1,
"campaign_banner_url" => 1,
"campaign_creative_type" => 1,
),
"campaign_black_list_white_list_info" => array
(
"black_list_app_ids" => 1,
"black_list_device_ids" => 1,
"black_list_ip_addresses" => 1,
"white_list_app_ids" => 1,
"white_list_device_ids" => 1,
"white_list_ip_addresses" => 1,
)
);
function array_keys_multi(array $array)
{
$keys = array();
foreach ($array as $key => $value) {
$keys[] = $key;
if (is_array($array[$key])) {
$keys = array_merge($keys, array_keys_multi($array[$key]));
}
}
return $keys;
}
$resArr=array();
$a=array_keys_multi($arr1);
$b=array_keys_multi($arr2);
$c=array_diff($a,$b);
if(count($c) > 0){
echo "There is differnce<br/>";
echo "<pre>";
print_r($c);
}else
echo "There is no differnce<br/>";
?>

PHP - udiff compare multiple values

I have two multidimenzional arrays and I need to compare them. Problem is that each subarray is unique by combination of permission_id, create and view. And I need to compare this arrays to check if there is such a unique subarray. The keys of subarrays can be different. So far I have this:
$updated_permissions = array(
0 => array(
'create' => 0,
'view' => 1,
'permission_id' => "87"
),
1 => array(
'create' => 0,
'view' => 1,
'permission_id' => "11"
),
2 => array(
'create' => 1,
'view' => 0,
'permission_id' => "11"
),
3 => array(
'create' => 0,
'view' => 1,
'permission_id' => "18"
)
);
$origin_permissions = array(
0 => array(
'create' => 0,
'view' => 1,
'permission_id' => "8"
),
1 => array(
'create' => 0,
'view' => 1,
'permission_id' => "11"
),
2 => array(
'create' => 1,
'view' => 0,
'permission_id' => "12"
)
);
$arrdiff = array_merge(
array_udiff($origin_permissions, $updated_permissions, 'udiffCompare'),
array_udiff($updated_permissions, $origin_permissions, 'udiffCompare')
);
function udiffCompare($a, $b) {
return $a['permission_id'] - $b['permission_id'];
}
print_r($arrdiff);
but that compare only permission_id so result is this:
[0] => Array (
[create] => 0
[view] => 1
[permission_id] => 8
)
[1] => Array (
[create] => 1
[view] => 0
[permission_id] => 12
)
[2] => Array (
[create] => 0
[view] => 1
[permission_id] => 87
)
[3] => Array (
[create] => 0
[view] => 1
[permission_id] => 18
)
while I need to compare also if create and view are same. So result I want to have is this (with permission_id 11 which has different create and view):
[0] => Array (
[create] => 0
[view] => 1
[permission_id] => 8
)
[1] => Array (
[create] => 1
[view] => 0
[permission_id] => 12
)
[2] => Array (
[create] => 0
[view] => 1
[permission_id] => 87
)
[3] => Array (
[create] => 0
[view] => 1
[permission_id] => 18
)
[4] => Array (
[create] => 1
[view] => 0
[permission_id] => 11
)
This code is also here
Like this ?
function udiffCompare($a, $b) {
if ($a['permission_id'] !== $b['permission_id'] || $a['view'] !== $b['view'] || $a['create'] !== $b['create']){
return 1;
}
}

Does PHP have a function that returns the correct file extension given a valid content type?

Does PHP have a function that returns a file extension given a content type?
I'm looking for something that works like:
<?php
function getFileExtension($contentType)
{
if ($contentType === 'image/png')
{
return '.png';
}
elseif ($contentType === 'image/jpg')
{
return '.jpg';
}
elseif ($contentType === 'application/zip')
{
return '.zip';
}
else
{
return FALSE;
}
}
The goal is to use a library function that has all content types handled. Based on the pattern above, I guess I could roll my own with something like this:
<?php
function getFileExtension($contentType)
{
$pieces = explode('/', $contentType);
return '.' . array_pop($pieces);
}
... but that seems janky. Anybody know of an already authored PHP solution? LMK. Thanks!
Given the limited number of file types stored within my application's database, the following class/method was an acceptable solution.
<?php
class AppUtil
{
public static function FileExt($contentType)
{
$map = array(
'application/pdf' => '.pdf',
'application/zip' => '.zip',
'image/gif' => '.gif',
'image/jpeg' => '.jpg',
'image/png' => '.png',
'text/css' => '.css',
'text/html' => '.html',
'text/javascript' => '.js',
'text/plain' => '.txt',
'text/xml' => '.xml',
);
if (isset($map[$contentType]))
{
return $map[$contentType];
}
// HACKISH CATCH ALL (WHICH IN MY CASE IS
// PREFERRED OVER THROWING AN EXCEPTION)
$pieces = explode('/', $contentType);
return '.' . array_pop($pieces);
}
}
echo AppUtil::FileExt('application/zip'); // prints '.zip'
Before settling on the above solution though, I did some searching on Google (as suggested by #whichdan) and found the following "extension to MIME type" mapping resource.
http://www.webmaster-toolkit.com/mime-types.shtml
After doing some analysis on the data presented in the above URL it became clear that there isn't a definitive solution for this problem (which is probably why there isn't a "content type to file extension" function in PHP).
To illustrate this fact for the benefit of the Stack Overflow community, I parsed the data presented in the above URL and split each content type into one of two categories - either "DEFINITIVE" OR "AMBIGUOUS". Running var_export on each of my "post parse" arrays results in the following PHP code.
<?php
// DEFINITIVE "CONTENT TYPE TO FILE EXTENSION" MAPPINGS
$definitive = array (
'application/x-authorware-bin' => '.aab',
'application/x-authorware-map' => '.aam',
'application/x-authorware-seg' => '.aas',
'text/vnd.abc' => '.abc',
'video/animaflex' => '.afl',
'application/x-aim' => '.aim',
'text/x-audiosoft-intra' => '.aip',
'application/x-navi-animation' => '.ani',
'application/x-nokia-9000-communicator-add-on-software' => '.aos',
'application/mime' => '.aps',
'application/arj' => '.arj',
'image/x-jg' => '.art',
'text/asp' => '.asp',
'application/x-mplayer2' => '.asx',
'video/x-ms-asf-plugin' => '.asx',
'audio/x-au' => '.au',
'application/x-troff-msvideo' => '.avi',
'video/avi' => '.avi',
'video/msvideo' => '.avi',
'video/x-msvideo' => '.avi',
'video/avs-video' => '.avs',
'application/x-bcpio' => '.bcpio',
'application/mac-binary' => '.bin',
'application/macbinary' => '.bin',
'application/x-binary' => '.bin',
'application/x-macbinary' => '.bin',
'image/x-windows-bmp' => '.bmp',
'application/x-bzip' => '.bz',
'application/vnd.ms-pki.seccat' => '.cat',
'application/clariscad' => '.ccad',
'application/x-cocoa' => '.cco',
'application/cdf' => '.cdf',
'application/x-cdf' => '.cdf',
'application/java' => '.class',
'application/java-byte-code' => '.class',
'application/x-java-class' => '.class',
'application/x-cpio' => '.cpio',
'application/mac-compactpro' => '.cpt',
'application/x-compactpro' => '.cpt',
'application/x-cpt' => '.cpt',
'application/pkcs-crl' => '.crl',
'application/pkix-crl' => '.crl',
'application/x-x509-user-cert' => '.crt',
'application/x-csh' => '.csh',
'text/x-script.csh' => '.csh',
'application/x-pointplus' => '.css',
'text/css' => '.css',
'application/x-deepv' => '.deepv',
'video/dl' => '.dl',
'video/x-dl' => '.dl',
'application/commonground' => '.dp',
'application/drafting' => '.drw',
'application/x-dvi' => '.dvi',
'drawing/x-dwf (old)' => '.dwf',
'model/vnd.dwf' => '.dwf',
'application/acad' => '.dwg',
'application/dxf' => '.dxf',
'text/x-script.elisp' => '.el',
'application/x-bytecode.elisp (compiled elisp)' => '.elc',
'application/x-elc' => '.elc',
'application/x-esrehber' => '.es',
'text/x-setext' => '.etx',
'application/envoy' => '.evy',
'application/vnd.fdf' => '.fdf',
'application/fractals' => '.fif',
'image/fif' => '.fif',
'video/fli' => '.fli',
'video/x-fli' => '.fli',
'text/vnd.fmi.flexstor' => '.flx',
'video/x-atomic3d-feature' => '.fmf',
'image/vnd.fpx' => '.fpx',
'image/vnd.net-fpx' => '.fpx',
'application/freeloader' => '.frl',
'image/g3fax' => '.g3',
'image/gif' => '.gif',
'video/gl' => '.gl',
'video/x-gl' => '.gl',
'application/x-gsp' => '.gsp',
'application/x-gss' => '.gss',
'application/x-gtar' => '.gtar',
'multipart/x-gzip' => '.gzip',
'application/x-hdf' => '.hdf',
'text/x-script' => '.hlb',
'application/hlp' => '.hlp',
'application/x-winhelp' => '.hlp',
'application/binhex' => '.hqx',
'application/binhex4' => '.hqx',
'application/mac-binhex' => '.hqx',
'application/mac-binhex40' => '.hqx',
'application/x-binhex40' => '.hqx',
'application/x-mac-binhex40' => '.hqx',
'application/hta' => '.hta',
'text/x-component' => '.htc',
'text/webviewhtml' => '.htt',
'x-conference/x-cooltalk' => '.ice ',
'image/x-icon' => '.ico',
'application/x-ima' => '.ima',
'application/x-httpd-imap' => '.imap',
'application/inf' => '.inf ',
'application/x-internett-signup' => '.ins',
'application/x-ip2' => '.ip ',
'video/x-isvideo' => '.isu',
'audio/it' => '.it',
'application/x-inventor' => '.iv',
'i-world/i-vrml' => '.ivr',
'application/x-livescreen' => '.ivy',
'audio/x-jam' => '.jam ',
'application/x-java-commerce' => '.jcm ',
'image/x-jps' => '.jps',
'application/x-javascript' => '.js ',
'image/jutvision' => '.jut',
'music/x-karaoke' => '.kar',
'application/x-ksh' => '.ksh',
'text/x-script.ksh' => '.ksh',
'audio/x-liveaudio' => '.lam',
'application/lha' => '.lha',
'application/x-lha' => '.lha',
'application/x-lisp' => '.lsp ',
'text/x-script.lisp' => '.lsp ',
'text/x-la-asf' => '.lsx',
'application/x-lzh' => '.lzh',
'application/lzx' => '.lzx',
'application/x-lzx' => '.lzx',
'text/x-m' => '.m',
'audio/x-mpequrl' => '.m3u ',
'application/x-troff-man' => '.man',
'application/x-navimap' => '.map',
'application/mbedlet' => '.mbd',
'application/x-magic-cap-package-1.0' => '.mc$',
'application/mcad' => '.mcd',
'application/x-mathcad' => '.mcd',
'image/vasa' => '.mcf',
'text/mcf' => '.mcf',
'application/netmc' => '.mcp',
'application/x-troff-me' => '.me ',
'application/x-frame' => '.mif',
'application/x-mif' => '.mif',
'www/mime' => '.mime ',
'audio/x-vnd.audioexplosion.mjuicemediafile' => '.mjf',
'video/x-motion-jpeg' => '.mjpg ',
'application/x-meme' => '.mm',
'audio/mod' => '.mod',
'audio/x-mod' => '.mod',
'audio/x-mpeg' => '.mp2',
'video/x-mpeq2a' => '.mp2',
'audio/mpeg3' => '.mp3',
'audio/x-mpeg-3' => '.mp3',
'application/vnd.ms-project' => '.mpp',
'application/marc' => '.mrc',
'application/x-troff-ms' => '.ms',
'application/x-vnd.audioexplosion.mzz' => '.mzz',
'application/vnd.nokia.configuration-message' => '.ncm',
'application/x-mix-transfer' => '.nix',
'application/x-conference' => '.nsc',
'application/x-navidoc' => '.nvd',
'application/oda' => '.oda',
'application/x-omc' => '.omc',
'application/x-omcdatamaker' => '.omcd',
'application/x-omcregerator' => '.omcr',
'text/x-pascal' => '.p',
'application/pkcs10' => '.p10',
'application/x-pkcs10' => '.p10',
'application/pkcs-12' => '.p12',
'application/x-pkcs12' => '.p12',
'application/x-pkcs7-signature' => '.p7a',
'application/x-pkcs7-certreqresp' => '.p7r',
'application/pkcs7-signature' => '.p7s',
'text/pascal' => '.pas',
'image/x-portable-bitmap' => '.pbm ',
'application/vnd.hp-pcl' => '.pcl',
'application/x-pcl' => '.pcl',
'image/x-pict' => '.pct',
'image/x-pcx' => '.pcx',
'application/pdf' => '.pdf',
'audio/make.my.funk' => '.pfunk',
'image/x-portable-graymap' => '.pgm',
'image/x-portable-greymap' => '.pgm',
'application/x-newton-compatible-pkg' => '.pkg',
'application/vnd.ms-pki.pko' => '.pko',
'text/x-script.perl' => '.pl',
'application/x-pixclscript' => '.plx',
'text/x-script.perl-module' => '.pm',
'application/x-portable-anymap' => '.pnm',
'image/x-portable-anymap' => '.pnm',
'model/x-pov' => '.pov',
'image/x-portable-pixmap' => '.ppm',
'application/powerpoint' => '.ppt',
'application/x-mspowerpoint' => '.ppt',
'application/x-freelance' => '.pre',
'paleovu/x-pv' => '.pvu',
'text/x-script.phyton' => '.py ',
'applicaiton/x-bytecode.python' => '.pyc ',
'audio/vnd.qcelp' => '.qcp ',
'video/x-qtc' => '.qtc',
'audio/x-realaudio' => '.ra',
'application/x-cmu-raster' => '.ras',
'image/x-cmu-raster' => '.ras',
'text/x-script.rexx' => '.rexx ',
'image/vnd.rn-realflash' => '.rf',
'image/x-rgb' => '.rgb ',
'application/vnd.rn-realmedia' => '.rm',
'audio/mid' => '.rmi',
'application/ringing-tones' => '.rng',
'application/vnd.nokia.ringing-tone' => '.rng',
'application/vnd.rn-realplayer' => '.rnx ',
'image/vnd.rn-realpix' => '.rp ',
'text/vnd.rn-realtext' => '.rt',
'application/x-rtf' => '.rtf',
'video/vnd.rn-realvideo' => '.rv',
'audio/s3m' => '.s3m ',
'application/x-lotusscreencam' => '.scm',
'text/x-script.guile' => '.scm',
'text/x-script.scheme' => '.scm',
'video/x-scm' => '.scm',
'application/sdp' => '.sdp ',
'application/x-sdp' => '.sdp ',
'application/sounder' => '.sdr',
'application/sea' => '.sea',
'application/x-sea' => '.sea',
'application/set' => '.set',
'application/x-sh' => '.sh',
'text/x-script.sh' => '.sh',
'audio/x-psid' => '.sid',
'application/x-sit' => '.sit',
'application/x-stuffit' => '.sit',
'application/x-seelogo' => '.sl ',
'audio/x-adpcm' => '.snd',
'application/solids' => '.sol',
'application/x-pkcs7-certificates' => '.spc ',
'application/futuresplash' => '.spl',
'application/streamingmedia' => '.ssm ',
'application/vnd.ms-pki.certstore' => '.sst',
'application/sla' => '.stl',
'application/vnd.ms-pki.stl' => '.stl',
'application/x-navistyle' => '.stl',
'application/x-sv4cpio' => '.sv4cpio',
'application/x-sv4crc' => '.sv4crc',
'x-world/x-svr' => '.svr',
'application/x-shockwave-flash' => '.swf',
'application/x-tar' => '.tar',
'application/toolbook' => '.tbk',
'application/x-tcl' => '.tcl',
'text/x-script.tcl' => '.tcl',
'text/x-script.tcsh' => '.tcsh',
'application/x-tex' => '.tex',
'application/plain' => '.text',
'application/gnutar' => '.tgz',
'audio/tsp-audio' => '.tsi',
'application/dsptype' => '.tsp',
'audio/tsplayer' => '.tsp',
'text/tab-separated-values' => '.tsv',
'text/x-uil' => '.uil',
'application/i-deas' => '.unv',
'application/x-ustar' => '.ustar',
'multipart/x-ustar' => '.ustar',
'application/x-cdlink' => '.vcd',
'text/x-vcalendar' => '.vcs',
'application/vda' => '.vda',
'video/vdo' => '.vdo',
'application/groupwise' => '.vew ',
'application/vocaltec-media-desc' => '.vmd ',
'application/vocaltec-media-file' => '.vmf',
'audio/voc' => '.voc',
'audio/x-voc' => '.voc',
'video/vosaic' => '.vos',
'audio/voxware' => '.vox',
'audio/x-twinvq' => '.vqf',
'application/x-vrml' => '.vrml',
'x-world/x-vrt' => '.vrt',
'application/wordperfect6.1' => '.w61',
'audio/wav' => '.wav',
'audio/x-wav' => '.wav',
'application/x-qpro' => '.wb1',
'image/vnd.wap.wbmp' => '.wbmp',
'application/vnd.xara' => '.web',
'application/x-123' => '.wk1',
'windows/metafile' => '.wmf',
'text/vnd.wap.wml' => '.wml',
'application/vnd.wap.wmlc' => '.wmlc ',
'text/vnd.wap.wmlscript' => '.wmls',
'application/vnd.wap.wmlscriptc' => '.wmlsc ',
'application/x-wpwin' => '.wpd',
'application/x-lotus' => '.wq1',
'application/mswrite' => '.wri',
'application/x-wri' => '.wri',
'text/scriplet' => '.wsc',
'application/x-wintalk' => '.wtk ',
'image/x-xbitmap' => '.xbm',
'image/x-xbm' => '.xbm',
'image/xbm' => '.xbm',
'video/x-amt-demorun' => '.xdr',
'xgl/drawing' => '.xgz',
'image/vnd.xiff' => '.xif',
'audio/xm' => '.xm',
'application/xml' => '.xml',
'text/xml' => '.xml',
'xgl/movie' => '.xmz',
'application/x-vnd.ls-xpix' => '.xpix',
'image/xpm' => '.xpm',
'video/x-amt-showrun' => '.xsr',
'image/x-xwd' => '.xwd',
'image/x-xwindowdump' => '.xwd',
'application/x-compress' => '.z',
'application/x-zip-compressed' => '.zip',
'application/zip' => '.zip',
'multipart/x-zip' => '.zip',
'text/x-script.zsh' => '.zsh',
);
...and...
<?php
// AMBIGUOUS "CONTENT TYPE TO FILE EXTENSION" MAPPINGS
$ambiguous = array (
'x-world/x-3dmf' =>
array (
0 => '.3dm',
1 => '.3dmf',
2 => '.qd3 ',
3 => '.qd3d ',
),
'application/octet-stream' =>
array (
0 => '.a',
1 => '.arc',
2 => '.arj',
3 => '.bin',
4 => '.com',
5 => '.dump',
6 => '.exe',
7 => '.lha',
8 => '.lhx',
9 => '.lzh',
10 => '.lzx',
11 => '.o',
12 => '.psd',
13 => '.saveme',
14 => '.uu',
15 => '.zoo',
),
'text/html' =>
array (
0 => '.acgi',
1 => '.htm',
2 => '.html',
3 => '.htmls',
4 => '.htx ',
5 => '.shtml ',
),
'application/postscript' =>
array (
0 => '.ai',
1 => '.eps',
2 => '.ps',
),
'audio/aiff' =>
array (
0 => '.aif',
1 => '.aifc',
2 => '.aiff',
),
'audio/x-aiff' =>
array (
0 => '.aif',
1 => '.aifc',
2 => '.aiff',
),
'video/x-ms-asf' =>
array (
0 => '.asf',
1 => '.asx',
),
'text/x-asm' =>
array (
0 => '.asm',
1 => '.s',
),
'audio/basic' =>
array (
0 => '.au',
1 => '.snd',
),
'image/bmp' =>
array (
0 => '.bm',
1 => '.bmp',
),
'application/book' =>
array (
0 => '.boo',
1 => '.book',
),
'application/x-bzip2' =>
array (
0 => '.boz',
1 => '.bz2',
),
'application/x-bsh' =>
array (
0 => '.bsh',
1 => '.sh',
2 => '.shar',
),
'text/plain' =>
array (
0 => '.c',
1 => '.c++',
2 => '.cc',
3 => '.com',
4 => '.conf',
5 => '.cxx',
6 => '.def',
7 => '.f',
8 => '.f90',
9 => '.for',
10 => '.g',
11 => '.h',
12 => '.hh',
13 => '.idc',
14 => '.jav',
15 => '.java',
16 => '.list',
17 => '.log ',
18 => '.lst ',
19 => '.m',
20 => '.mar',
21 => '.pl',
22 => '.sdml',
23 => '.text',
24 => '.txt',
),
'text/x-c' =>
array (
0 => '.c',
1 => '.cc',
2 => '.cpp',
),
'application/x-netcdf' =>
array (
0 => '.cdf',
1 => '.nc',
),
'application/pkix-cert' =>
array (
0 => '.cer',
1 => '.crt',
),
'application/x-x509-ca-cert' =>
array (
0 => '.cer',
1 => '.crt',
2 => '.der',
),
'application/x-chat' =>
array (
0 => '.cha',
1 => '.chat',
),
'application/x-director' =>
array (
0 => '.dcr',
1 => '.dir',
2 => '.dxr',
),
'video/x-dv' =>
array (
0 => '.dif',
1 => '.dv',
),
'application/msword' =>
array (
0 => '.doc',
1 => '.dot',
2 => '.w6w',
3 => '.wiz',
4 => '.word ',
),
'image/vnd.dwg' =>
array (
0 => '.dwg',
1 => '.dxf',
2 => '.svf',
),
'image/x-dwg' =>
array (
0 => '.dwg',
1 => '.dxf',
2 => '.svf',
),
'application/x-envoy' =>
array (
0 => '.env',
1 => '.evy',
),
'text/x-fortran' =>
array (
0 => '.f',
1 => '.f77',
2 => '.f90',
3 => '.for',
),
'image/florian' =>
array (
0 => '.flo',
1 => '.turbot',
),
'audio/make' =>
array (
0 => '.funk',
1 => '.my',
2 => '.pfunk',
),
'audio/x-gsm' =>
array (
0 => '.gsd',
1 => '.gsm',
),
'application/x-compressed' =>
array (
0 => '.gz',
1 => '.tgz',
2 => '.z',
3 => '.zip',
),
'application/x-gzip' =>
array (
0 => '.gz',
1 => '.gzip',
),
'text/x-h' =>
array (
0 => '.h',
1 => '.hh',
),
'application/x-helpfile' =>
array (
0 => '.help',
1 => '.hlp',
),
'application/vnd.hp-hpgl' =>
array (
0 => '.hgl',
1 => '.hpg',
2 => '.hpgl',
),
'image/ief' =>
array (
0 => '.ief',
1 => '.iefs',
),
'application/iges' =>
array (
0 => '.iges',
1 => '.igs',
),
'model/iges' =>
array (
0 => '.iges ',
1 => '.igs',
),
'text/x-java-source' =>
array (
0 => '.jav',
1 => '.java ',
),
'image/jpeg' =>
array (
0 => '.jfif',
1 => '.jfif-tbnl',
2 => '.jpe',
3 => '.jpeg',
4 => '.jpg ',
),
'image/pjpeg' =>
array (
0 => '.jfif',
1 => '.jpe',
2 => '.jpeg',
3 => '.jpg ',
),
'audio/midi' =>
array (
0 => '.kar',
1 => '.mid',
2 => '.midi',
),
'audio/nspaudio' =>
array (
0 => '.la ',
1 => '.lma',
),
'audio/x-nspaudio' =>
array (
0 => '.la ',
1 => '.lma',
),
'application/x-latex' =>
array (
0 => '.latex ',
1 => '.ltx',
),
'video/mpeg' =>
array (
0 => '.m1v',
1 => '.m2v',
2 => '.mp2',
3 => '.mp3',
4 => '.mpa',
5 => '.mpe',
6 => '.mpeg',
7 => '.mpg',
),
'audio/mpeg' =>
array (
0 => '.m2a',
1 => '.mp2',
2 => '.mpa',
3 => '.mpg',
4 => '.mpga',
),
'message/rfc822' =>
array (
0 => '.mht',
1 => '.mhtml',
2 => '.mime ',
),
'application/x-midi' =>
array (
0 => '.mid',
1 => '.midi',
),
'audio/x-mid' =>
array (
0 => '.mid',
1 => '.midi',
),
'audio/x-midi' =>
array (
0 => '.mid',
1 => '.midi',
),
'music/crescendo' =>
array (
0 => '.mid',
1 => '.midi',
),
'x-music/x-midi' =>
array (
0 => '.mid',
1 => '.midi',
),
'application/base64' =>
array (
0 => '.mm',
1 => '.mme',
),
'video/quicktime' =>
array (
0 => '.moov',
1 => '.mov',
2 => '.qt',
),
'video/x-sgi-movie' =>
array (
0 => '.movie',
1 => '.mv',
),
'video/x-mpeg' =>
array (
0 => '.mp2',
1 => '.mp3',
),
'application/x-project' =>
array (
0 => '.mpc',
1 => '.mpt',
2 => '.mpv',
3 => '.mpx',
),
'image/naplps' =>
array (
0 => '.nap',
1 => '.naplps',
),
'image/x-niff' =>
array (
0 => '.nif',
1 => '.niff',
),
'application/pkcs7-mime' =>
array (
0 => '.p7c',
1 => '.p7m',
),
'application/x-pkcs7-mime' =>
array (
0 => '.p7c',
1 => '.p7m',
),
'application/pro_eng' =>
array (
0 => '.part ',
1 => '.prt',
),
'chemical/x-pdb' =>
array (
0 => '.pdb',
1 => '.xyz',
),
'image/pict' =>
array (
0 => '.pic',
1 => '.pict',
),
'image/x-xpixmap' =>
array (
0 => '.pm',
1 => '.xpm',
),
'application/x-pagemaker' =>
array (
0 => '.pm4 ',
1 => '.pm5',
),
'image/png' =>
array (
0 => '.png',
1 => '.x-png',
),
'application/mspowerpoint' =>
array (
0 => '.pot',
1 => '.pps',
2 => '.ppt',
3 => '.ppz',
),
'application/vnd.ms-powerpoint' =>
array (
0 => '.pot',
1 => '.ppa',
2 => '.pps',
3 => '.ppt',
4 => '.pwz ',
),
'image/x-quicktime' =>
array (
0 => '.qif',
1 => '.qti',
2 => '.qtif',
),
'audio/x-pn-realaudio' =>
array (
0 => '.ra',
1 => '.ram',
2 => '.rm',
3 => '.rmm ',
4 => '.rmp',
),
'audio/x-pn-realaudio-plugin' =>
array (
0 => '.ra',
1 => '.rmp',
2 => '.rpm',
),
'image/cmu-raster' =>
array (
0 => '.ras',
1 => '.rast',
),
'application/x-troff' =>
array (
0 => '.roff',
1 => '.t',
2 => '.tr',
),
'text/richtext' =>
array (
0 => '.rt',
1 => '.rtf',
2 => '.rtx',
),
'application/rtf' =>
array (
0 => '.rtf',
1 => '.rtx',
),
'application/x-tbook' =>
array (
0 => '.sbk ',
1 => '.tbk',
),
'text/sgml' =>
array (
0 => '.sgm ',
1 => '.sgml',
),
'text/x-sgml' =>
array (
0 => '.sgm ',
1 => '.sgml',
),
'application/x-shar' =>
array (
0 => '.sh',
1 => '.shar',
),
'text/x-server-parsed-html' =>
array (
0 => '.shtml',
1 => '.ssi',
),
'application/x-koan' =>
array (
0 => '.skd',
1 => '.skm ',
2 => '.skp ',
3 => '.skt ',
),
'application/smil' =>
array (
0 => '.smi ',
1 => '.smil ',
),
'text/x-speech' =>
array (
0 => '.spc ',
1 => '.talk',
),
'application/x-sprite' =>
array (
0 => '.spr',
1 => '.sprite ',
),
'application/x-wais-source' =>
array (
0 => '.src',
1 => '.wsrc',
),
'application/step' =>
array (
0 => '.step',
1 => '.stp',
),
'application/x-world' =>
array (
0 => '.svr',
1 => '.wrl',
),
'application/x-texinfo' =>
array (
0 => '.texi',
1 => '.texinfo',
),
'image/tiff' =>
array (
0 => '.tif',
1 => '.tiff',
),
'image/x-tiff' =>
array (
0 => '.tif',
1 => '.tiff',
),
'text/uri-list' =>
array (
0 => '.uni',
1 => '.unis',
2 => '.uri',
3 => '.uris',
),
'text/x-uuencode' =>
array (
0 => '.uu',
1 => '.uue',
),
'video/vivo' =>
array (
0 => '.viv',
1 => '.vivo',
),
'video/vnd.vivo' =>
array (
0 => '.viv',
1 => '.vivo',
),
'audio/x-twinvq-plugin' =>
array (
0 => '.vqe',
1 => '.vql',
),
'model/vrml' =>
array (
0 => '.vrml',
1 => '.wrl',
2 => '.wrz',
),
'x-world/x-vrml' =>
array (
0 => '.vrml',
1 => '.wrl',
2 => '.wrz',
),
'application/x-visio' =>
array (
0 => '.vsd',
1 => '.vst',
2 => '.vsw ',
),
'application/wordperfect6.0' =>
array (
0 => '.w60',
1 => '.wp5',
),
'application/wordperfect' =>
array (
0 => '.wp',
1 => '.wp5',
2 => '.wp6 ',
3 => '.wpd',
),
'application/excel' =>
array (
0 => '.xl',
1 => '.xla',
2 => '.xlb',
3 => '.xlc',
4 => '.xld ',
5 => '.xlk',
6 => '.xll',
7 => '.xlm',
8 => '.xls',
9 => '.xlt',
10 => '.xlv',
11 => '.xlw',
),
'application/x-excel' =>
array (
0 => '.xla',
1 => '.xlb',
2 => '.xlc',
3 => '.xld ',
4 => '.xlk',
5 => '.xll',
6 => '.xlm',
7 => '.xls',
8 => '.xlt',
9 => '.xlv',
10 => '.xlw',
),
'application/x-msexcel' =>
array (
0 => '.xla',
1 => '.xls',
2 => '.xlw',
),
'application/vnd.ms-excel' =>
array (
0 => '.xlb',
1 => '.xlc',
2 => '.xll',
3 => '.xlm',
4 => '.xls',
5 => '.xlw',
),
);
It's very easy to create your own class to handle this.
Google search for "mimetype file extension list"
Create a static class with a mimetype => extension list stored in an array, and then write a findByMimeType and findByExtension method. You can use array_search to search by value.

Categories