missing function to return single array element?
Posted: Tue Mar 23, 2004 7:38 am
Really, I am no PHP newbie and I have searched the array-functions list thoroughly (at least I think I did.)
But... it seems to me there is no way to do this in ONE step:
Create an array and have one element returned as a string.
in Java / JavaScript you can simply append the desired elements index to the function creating the array like this:
In PHP it seems you have to code:
Sure shift() and pop() can do when it is the first or the last element you want and you don't need the original array anymore, but that is not always the case.
For example:
With an image file upload, you can determine the image type by calling getimagesize() on the file. The image type information is in the 3rd element of the array returned.
Now it would be so nice to code:
Or wouldn't it?!
Please tell me that I am just plain blind and that, of course, there is a way to do this in PHP!
Thanx!
But... it seems to me there is no way to do this in ONE step:
Create an array and have one element returned as a string.
in Java / JavaScript you can simply append the desired elements index to the function creating the array like this:
Code: Select all
var myFilename = myFileWithExtention.slice('.')ї0];Code: Select all
$tmp = explode('.', $myFileWithExtention);
$myFilename = $tmpї0]For example:
With an image file upload, you can determine the image type by calling getimagesize() on the file. The image type information is in the 3rd element of the array returned.
Now it would be so nice to code:
Code: Select all
$image_format = getimagesize($ul_file)ї2];Please tell me that I am just plain blind and that, of course, there is a way to do this in PHP!
Thanx!