hi! heres the code to filter odd and even numbers. the problem is, "Array ( [1]...." appears... i think because of print_r.. is there any way to display the odd and even numbers without "Array ( [1]...." I want to display pure odd and even numbers.. thank you.
function odd($var)
{
return($var & 1);
}
function even($var)
{
return(!($var & 1));
}
$array1 = array($a,$b,$c,$d,$e,$f,$g,$h,$i,$j);
$array2 = array($a,$b,$c,$d,$e,$f,$g,$h,$i,$j);
echo "<BR>Odd :\n";
print_r(array_filter($array1, "odd"));
echo "<BR>Even:\n";
print_r(array_filter($array2, "even"));
print r alternative
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: print r alternative
use a foreach() -- or other type of loop -- to output each array element.
You could also simply do the follow if all you need a delimited list.
You could also simply do the follow if all you need a delimited list.
Code: Select all
echo implode(',' $youarray);