PHP调用数组值

时间:2011-10-17 19:15:20

标签: php arrays variables

首先我有这些变量:

$asd=$current[0]->icon['data']; // -it will print  /ig/images/weather/mostly_cloudy.gif
$icons["/ig/images/weather/rain.gif"][0]; // it will print rain.gif

我想看看rain.gif输出。我正在努力做到这一点。

echo $icons[$asd][0]; // I will get error. 

我想用变量获取此输出。

$icons["/ig/images/weather/rain.gif"][0]; // it will print rain.gif

代码错了吗?

echo $icons[$asd][0];

请帮忙。

感谢evryone。对不起我的英文。

我该怎么办呢。

1 个答案:

答案 0 :(得分:1)

你正在寻找basename

echo basename('/ig/images/weather/mostly_cloudy.gif'); // output: mostly_cloudy.gif');
echo basename('/ig/images/weather/rain.gif');          // output: rain.gif

假设$asd(在您的示例中)是图像的路径,而您只是在寻找文件名部分。

虽然你的问题不是100%清楚。

相关问题