
Untitled
By: a guest on
Jul 31st, 2012 | syntax:
None | size: 1.27 KB | hits: 15 | expires: Never
PHP - foreach loop
$idx = 0;
foreach($this->categories as $category)
{
echo "n".($idx++ ? '| ' : '').'<a href="'.KM_Helpers::getCategoryURL($category).'">'.$category['name'].'</a>';
}
$myarray = array(2, 8, 21, 22);
$idx = 0;
$myarray = array(2, 8, 21, 22);
foreach($this->categories as $category)
{
if (!in_array($category['id'], $myarray)) {
continue; // skip it if the id isn't in your array of accceptable IDs
}
echo "n".($idx++ ? '| ' : '').'<a href="'.KM_Helpers::getCategoryURL($category).'">'.$category['name'].'</a>';
}
foreach ($myarray as $id)
{
$category = $this->categories[$id];
echo "n".($idx++ ? '| ' : '') .
'<a href="' . KM_Helpers::getCategoryURL($category) . '">' .
$category['name'] . '</a>';
}
$idx = 0;
$myarray = array(2, 8, 21, 22);
foreach($this->categories as $category)
{
if(in_array($category['id'], $myarray)
{
echo "n".($idx++ ? '| ' : '').'<a href="'.KM_Helpers::getCategoryURL($category).'">'.$category['name'].'</a>';
}
}
$ids= array(2, 8, 21, 22);
$idx = 0;
foreach($this->categories as $id => $category){
if (in_array($category['id'] , $ids)) {
echo "n".($idx++ ? '| ' : '').'<a href="'.KM_Helpers::getCategoryURL($category).'">'.$category['name'].'</a>';
}
}