Page 1 of 1

print r alternative

Posted: Tue Apr 29, 2008 10:58 am
by sampaloc
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"));

Re: print r alternative

Posted: Tue Apr 29, 2008 11:14 am
by John Cartwright
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.

Code: Select all

echo implode(',' $youarray);