thinkphp for循环改变数组中的值错误,求教
dump($arr);array(10){[0]=>array(21){["id"]=>string(2)"88"........省略.........["pu_pic"...
dump($arr);
array(10) {
[0] => array(21) {
["id"] => string(2) "88"
........省略.........
["pu_pic"] => string(74) "1507/p_5594a950e92577.jpg|1507/p_5594a957e23c6.jpg|1507/p_5594a9518888.jpg"
........省略.........
}
[1] => array(21) {
[0] => array(21) {
["id"] => string(2) "88"
........省略.........
["pu_pic"] => string(74) "1507/p_5594a950e1789.jpg|1507/p_4444a951e23c6.jpg|1507/p_5594a9544fb44.jpg"
........省略.........
}
[2] => array(21) {
[0] => array(21) {
["id"] => string(2) "88"
........省略.........
["pu_pic"] => string(74) "1507/p_5594a950e1789.jpg|1507/p_4444a951e23c6.jpg|1507/p_5594a9544fb44.jpg"
........省略.........
}
代码:
循环改变$arr["pu_pic"]中的值
for($i=0;$i<count($arr);$i++){
if(strlen($arr[i]['pu_pic'])>30) //统计$arr["pu_pic"]中字符串个数
{
$thumb=explode('|',$arr[i]['pu_pic']);
$arr[i]['pu_pic']=$thumb[0];
}
dump($thumb);
}
dump($arr)为空值;
写错了
是dump($thumb)为空值;
整个$arr 为二维数组。 展开
array(10) {
[0] => array(21) {
["id"] => string(2) "88"
........省略.........
["pu_pic"] => string(74) "1507/p_5594a950e92577.jpg|1507/p_5594a957e23c6.jpg|1507/p_5594a9518888.jpg"
........省略.........
}
[1] => array(21) {
[0] => array(21) {
["id"] => string(2) "88"
........省略.........
["pu_pic"] => string(74) "1507/p_5594a950e1789.jpg|1507/p_4444a951e23c6.jpg|1507/p_5594a9544fb44.jpg"
........省略.........
}
[2] => array(21) {
[0] => array(21) {
["id"] => string(2) "88"
........省略.........
["pu_pic"] => string(74) "1507/p_5594a950e1789.jpg|1507/p_4444a951e23c6.jpg|1507/p_5594a9544fb44.jpg"
........省略.........
}
代码:
循环改变$arr["pu_pic"]中的值
for($i=0;$i<count($arr);$i++){
if(strlen($arr[i]['pu_pic'])>30) //统计$arr["pu_pic"]中字符串个数
{
$thumb=explode('|',$arr[i]['pu_pic']);
$arr[i]['pu_pic']=$thumb[0];
}
dump($thumb);
}
dump($arr)为空值;
写错了
是dump($thumb)为空值;
整个$arr 为二维数组。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询