我在foreach中有一个这样的关联数组:
foreach ($mArray as $aValue) {
foreach ($aValue as $key => $value) {
echo $html->find($key,$value)
}
}
它给我这样的输出:
bobby
johnny
现在我想获得最后一个字符,即y
,所以我这样做:
echo substr($TheString, -1);
但是这给了我:yy
因为它是一个多维数组所以它给了我每个数组的最后一个字符。我能做些什么来获得页面上的最后一个字符y
(..然后删掉)?
$last_char = '';
foreach ($mArray as $aValue) {
foreach ($aValue as $key => $value) {
if(substr($html->find($key,$value), -1) == 'y'){
$last_char = $html->find($key,$value);
}
}
}
echo $last_char;
这似乎对我有用
echo substr_replace($TheString,"",-3);
Try This:
echo substr($TheString, -1, 1);
或替换字符串删除y
$s="abcdey";
$m=substr($s,0,-1);
echo substr_replace($s,$m,0)
Try This:
$array = array(
"foo" => "jonny",
"bar" => "monny",
);
$i=0;
$con=count($array);
foreach($array as $key => $value)
{
$i++;
if($i==$con)
{
$s=$value;
$m=substr($value,0,-1);
$value=substr_replace($s,$m,0);
echo "Removed Y from array of last item =".$m."</br>";
}
echo $value."</br>";
}