How to increase $kk in echo by 1?
i am here not going ahead at this point
<?php
$count = 0;
$arrImg = array();
$arrtitle = array();
foreach ($feed->get_items() as $kk=> $item) {
$feedDescription = $item->get_content();
$feedTitle = $item->get_title();
//print_r($feedTitle);
$image = returnImage($feedDescription);
$image = scrapeImage($image);
$image = urldecode($image);
$arrimg[$count] = $image;
$arrtitle[$count] = $feedTitle;
//print_r("rajesh".$kk);
echo '<img class="slide-img-'.$kk.'" src="' .$arrimg[$kk]. '" />';
$count++;
// echo '<br />';
}
?&g开发者_运维百科t;
i want to add 1 to $kk in echo .but i tried many ways but didnt get hte soln
please help thanks
Just use pre-increment operator.
echo ++$kk;
But note this will increment $kk
itself.
To add one to echo, just do ($kk + 1)
.
<?php
$count = 0;
$arrImg = array();
$arrtitle = array();
foreach ($feed->get_items() as $kk=> $item) {
$feedDescription = $item->get_content();
$feedTitle = $item->get_title();
//print_r($feedTitle);
$image = returnImage($feedDescription);
$image = scrapeImage($image);
$image = urldecode($image);
$arrimg[$count] = $image;
$arrtitle[$count] = $feedTitle;
//print_r("rajesh".$kk);
echo '<img class="slide-img-'.($kk+1).'" src="' .$arrimg[$kk]. '" />';
$count++;
// echo '<br />';
}
?>
At what point do you want to increment the variable? You can use the incrementation operator ++
as either a prefix or suffix depending on the timing.
Here's some examples
$kk = 1; echo ++$kk, ' ', $kk;
// 2 2
$kk = 1; echo $kk++, ' ', $kk;
// 1 2
$kk = 1; echo $kk, ' ', $kk++, ' ', $kk;
// 1 1 2
I am not sure I understand, why don't you just do directly $bkk+1?
Also are you sure you want to set the image to $arrimg[$count] then call $arrimg[$kk].
I think you should use either $count or $kk for both.
精彩评论