我有这个数组
Array(
[0] => Array
(
[value] => /4/9/492.jpg
)
[1] => Array
(
[value] => /4/9/493.jpg
)
[2] => Array
(
[value] => /4/9/494.jpg
)
[3] => Array
(
[value] => /4/9/495.jpg
)
[4] => Array
(
[value] => /w/i/witbox_schwarz.jpg
)
)
我想在此方案后使用新文件名更改值。
$n = count($arr);
foreach ($arr as $key => $value) {
for ($i = 0; $i < $n; $i++) {
if ($key == $i) {
echo 'old filename is ' . $value . ' ... new filename will be ' . $prod_result['products_id'] . '_' . $key . '.' . pathinfo($value, PATHINFO_EXTENSION);
}
}
}
一切都很好,但我不能在foreach循环中从数组中获取旧值。
答案 0 :(得分:1)
正如我在我的系统中所做的那样完美无缺
$arr = [0 => ['value' => "/4/9/492.jpg"],1 => ['value' => "/4/9/493.jpg"],2 => ['value' => "/4/9/494.jpg"],3 => ['value' => "/4/9/495.jpg"],4 => ['value' => "/w/i/witbox_schwarz.jpg"]];
$n = count($arr);
foreach ($arr as $key => $value) {
for ($i = 0; $i < $n; $i++) {
if ($key == $i) {
echo 'old filename is ' . $value['value'] . ' ... new filename will be ' . $prod_result['products_id'] . '_' . $key . '.' . pathinfo($value['value'], PATHINFO_EXTENSION);
}
}
}