views:

46

answers:

0

Possible Duplicate:
Access array element from function call in php

For example:

    $info = pathinfo($fileName); 
header('Content-Description: File Transfer');
header('Content-Type: '.Mimetypes::get($info['extension']));

Notice here I am using $info['extension'] and $info derived from calling pathinfo($fileName).

So the question is why can I not do:

header('Content-Description: File Transfer');
header('Content-Type: '.Mimetypes::get(pathinfo($fileName)['extension']));

And get rid of $info entirely as all I really want is the extension from pathinfo. This may be considered bad practice but I know this type of thing can be done in javascript.

Another that comes to mind is:

$x = "1,2,3,4,5";
$y = explode(",",$x); 
$z = $y[0];    //here I know explode will give me an array with 5 elements

I want to do:

$z = explode(",","1,2,3,4,5")[0];    

Can someone explain this to me?