I am working with SimplePie and I cannot figure out how to output the count, or the key values for the loop.
Shouldn’t this
<?php foreach ($feed->get_items() as $item): ?>
<?php
$i = key($item);
echo $i;
?>
<?php endforeach; ?>
, or this
<?php foreach ($feed->get_items() as $item): ?>
<?php
$i = count($item);
echo $i;
?>
<?php endforeach; ?>
be outputting a unique number for each?
uniqid() Doesn’t work in this case, because I am running the loop twice on the page and trying to match up one list of elements with another based on ID.
A single argument used with
asis interpreted as a variable in which to store the value, not the key. If you want the key, you need to use=>in a manner like the following:As a sidenote, you’re using
key()andcount()on an item in the array, rather than the array as a whole, which is invalid. As far as I’m aware, there’s no guarantee thatkey()will work as you expect even if applied to the whole array. It’s meant for loops where you control the iteration, as with next.