I am trying to work with an external array that should transform my file endings into another string:
This is my fileTypes.php
:
return array(
'mp3' => 'fa-music',
'jpeg' => 'fa-picture-o',
);
And this is my index.php
:
$fileTypes = require('fileTypes.php');
$file = "mymusic.mp3"
$fileExt = strtolower(pathinfo($file, PATHINFO_EXTENSION));
echo $fileTypes['fileExt'];
I do not really get it run. I must have some basic problem in understanding :( I get an empty result. But the result I wish is fa-music
.
Your fileTypes.php
file would be like this:
$fileTypes = array(
'mp3' => 'fa-music',
'jpeg' => 'fa-picture-o',
);
Now, just include that file in your main script:
require('fileTypes.php');
$file = "mymusic.mp3";
$fileExt = strtolower(pathinfo($file, PATHINFO_EXTENSION));
echo $fileTypes[$fileExt];