0

I have an array

$this->input->post("first_array")={ one two three }

I need to create an array which will hold several arrays like that

so I am doing a 'fisrt_array' to hold the array, first verifiying that it is indeed an array, then if it is not set I put a 'not defined' string

array(
'fisrt_array' => is_array($this->input->post("first_array")) ? implode(' ',$this->input->post("first_array"))   : 'Not defined'
);

So if it is set, I implode the array that is saved in $this->input->post("first_array")

All is correct but I store the result like one two three instead of one,two,three

How can i save the array in that format?

If i do implode(',',$this->input->post("first_array") i would store one,two,three, with last not wanted comma..

edgarmtze
  • 24,683
  • 80
  • 235
  • 386
  • `$this->input->post("first_array")={ one two three }` this code will produce an error, please show us all the relevant lines! – Nir Alfasi Apr 21 '13 at 17:13
  • possible duplicate of [How to remove last comma (,) from array?](http://stackoverflow.com/questions/6368075/how-to-remove-last-comma-from-array) – Antony Apr 21 '13 at 17:13

1 Answers1

3

implode(',',$this->input->post("first_array") should not add a comma after the last element.

This should work for you. Having said that, you're declaring your array in a weird way.

Use $this->input->post['First_Array'] = array('One', 'Two', 'Three');

Edit: Also, just re-read the OP. If you just want to add your arrays to another array (in PHP, we refer to arrays of arrays as 'multidimensional arrays), just do:

second_array[] = $this->input->post['First_Array'];

Glitch Desire
  • 14,632
  • 7
  • 43
  • 55