1

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.

1
  • Besides your missing semicolon, you want to use the variable $fileExt as index and not the string fileExt (Add error reporting: ini_set("display_errors", 1); error_reporting(E_ALL);) Commented Apr 7, 2016 at 18:53

1 Answer 1

2

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];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.