Please tell me what this expression means $rss->items I actually dont know what is the use of this "->" Need help
It is a reference to a method or property of an object. In this case it is most likely a reference to the xml node items. You would probably see this when using the simpleXML library or another xml parser.
Thank You for the quick reply. Can you please tell me one more thing. In case I have this loop foreach ($rss->items as $item ) { } Show can I replace this loop? I mean what can replace "$rss->items as $item"? What I want to do is that I want to limit the rss shown, the above loop show all the rss feeds where I want to limit it to 10. So, can I replace this loop?
That line is saying, for every item in RSS (you can access it as $item which will change on every loop)... To limit it, easy. Add a variable before the loop (a counter), say $counter = 0; then the loop for each(.......) { // You do something with the $item, such as print it out, etc // Then add the counter $counter++; // Check if already more than 10 if($counter > 10) break; } or google on how to do a FOR loop
There are probably 50 ways to do this, (for, while, foreach). Here's quick way to limit to 10. $i = 1; foreach ($rss->items as $item ) { if($i <= 10){ //do stuff here } $i++; } PHP:
You may be able to use a for loop instead. Something like for($i=0; $i<=10; $i++) then iterate through the loop that way. But I'd have to see the entire loop. Could you post it?
Actually doing what you said or "michael.aulia michael.aulia" is a good idea but the problem is that if rss feeds are 100, then this loop will still run for 100 times, where I want to limit the loop from running 100 times + I want to show 10 feeds only Anyway to replace the loop?
Can you show an example of the XML. A for or do while loop is probably going to be the best way to do it.
Thanks, on first look I didnt see this part in your post "break; " This will do the trick, Thanks for the help. Anyway, I still wonder is we can replace the foreach loop
Can you tell me how bad the below code is, in terms of page opening time, and SEO if there is a while loop that runs for 62 times and this while loop is in IF loop which will run for 30 times. so while loop will run for 60 * 30 times.