Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php substr在数组中不工作 $photo[]=(字符串)$post->{'photo-caption'}; $photo_post[]=substr($photo,0320); $img[]=(字符串)$post->{'photo-url'}; 如果($pCount==$photoPosts) 对于($i=0;$i_Php_Arrays_Tumblr_Substr - Fatal编程技术网

Php substr在数组中不工作 $photo[]=(字符串)$post->{'photo-caption'}; $photo_post[]=substr($photo,0320); $img[]=(字符串)$post->{'photo-url'}; 如果($pCount==$photoPosts) 对于($i=0;$i

Php substr在数组中不工作 $photo[]=(字符串)$post->{'photo-caption'}; $photo_post[]=substr($photo,0320); $img[]=(字符串)$post->{'photo-url'}; 如果($pCount==$photoPosts) 对于($i=0;$i,php,arrays,tumblr,substr,Php,Arrays,Tumblr,Substr,如果要从$photo提取子字符串,应确保$photo是字符串而不是数组。请在赋值中保留$photo之后的[] 如果希望photo成为数组,请取消对数组的引用,如substr($photo[0],0320); 当然,在后一种情况下,您必须为数组提供适当的索引。如果您想从$photo提取子字符串,您应该确保$photo是字符串而不是数组。请在赋值中保留[]之后的$photo 如果希望photo成为数组,请取消对数组的引用,如substr($photo[0],0320); 当然,在后一种情况下,您必须

如果要从
$photo
提取子字符串,应确保
$photo
是字符串而不是数组。请在赋值中保留
$photo
之后的[]

如果希望photo成为数组,请取消对数组的引用,如
substr($photo[0],0320);


当然,在后一种情况下,您必须为数组提供适当的索引。

如果您想从
$photo
提取子字符串,您应该确保
$photo
是字符串而不是数组。请在赋值中保留[]之后的
$photo

如果希望photo成为数组,请取消对数组的引用,如
substr($photo[0],0320);


当然,在后一种情况下,您必须为数组提供适当的索引。

您所说的“不工作”是什么意思?任何错误消息或错误结果?为什么$photo[]是一个数组?它看起来像是一个简单的字符串!我想您应该看看PHP手册()。用于字符串类型数据的substr函数“不工作”是什么意思任何错误消息或错误结果?为什么$photo[]是一个数组?它看起来像是一个简单的字符串!我想您应该看看PHP手册()。用于字符串类型数据的substr函数
            $photo[] = (string) $post->{'photo-caption'}; 
            $photo_post[] = substr($photo,0,320);
            $img[] = (string) $post->{'photo-url'};
            if($pCount==$photoPosts)
            for($i=0;$i<$photoPosts;$i++)
            {
                if(isset($img[$i]))
                {

                echo "<div style='width:518px;height:250px;border-bottom: 1px solid;'><div style='width:210px;height:200px;float:left;'>".'<img style="width:200px;height:200px;" src="' . $img[$i] . '" />'."</div><div style='width:300px;height:50px;float:right;'>".$photo_post[$i]."</div></div><br>";
                }
            }
            $pCount=$pCount+1;