php question regarding arrays
Posted
by Martin
on Stack Overflow
See other posts from Stack Overflow
or by Martin
Published on 2010-03-30T04:40:52Z
Indexed on
2010/03/30
4:43 UTC
Read the original article
Hit count: 401
php
Hi there,
I'm a (complete) php noob and need a little help with something.
I'm working on a project whereby a user can select up to 6 categories via a form (I'm using ExpressionEngine). The output is like this:
"Cat1","Cat2","Cat3"
...and so on. The user can select up to 6 categories on that form.
What I need: even if my result is 3 categories I need to have 6 'cells' - for want of a better word - even if they're empty:
"Cat1","Cat2","Cat3","","",""
I've tried this:
<?php
$str = '(output goes here)';
print_r(explode(',', $str, 6));
?>
...but the output give me:
Array
(
[0] => Cat1
[1] => Cat2
[2] => Cat3
[3] =>
[4] =>
[5] =>
)
How do I get from that to this:
"Cat1","Cat2","Cat3","","",""
Does this make sense?
Thanks Martin
© Stack Overflow or respective owner