0

I know this won't take much time for experts here. But still please help me out

My Array output is like this

Array ( [0] => 1 [1] => 37 [2] => 1035 ) 1
Array ( [0] => 1 [1] => 37 [2] => 1035 ) mystatusmessage1

Array ( [0] => 4 [1] => 37 [2] => 2925 ) 2
Array ( [0] => 4 [1] => 37 [2] => 2925 ) mystatusmessage2

What I would like to get it is in a single string value like this so that I can insert into database.

1,37,1035,1,mystatusmessage1
4,37,2925,2,mystatusmessage2

How can I achieve that. I'm trying to do with foreach but still I'm not able to do it.

Thanks, Kimz

3
  • Try implode() with a comma as the http://php.net/manual/en/function.implode.php.
    – Rasclatt
    Commented Oct 9, 2014 at 6:24
  • yes i did that. but please check my array value above. i have to merge array values with the existing one. that i am not able to do. please can u help me Commented Oct 9, 2014 at 6:31
  • Where do you get the 1 and mystatusmessage1 outside the array from? Those are from $_POST is that right?
    – Rasclatt
    Commented Oct 9, 2014 at 7:16

2 Answers 2

0

use implode function to make string from array for example

if you have array like Array('a','b','c');

  implode(',',array('a','b','c') )

will return a,b,c as string

here first argument is your glue by which you want to join string

0

Here you go.

// Original array
$array  =   array(0 => 1, 1 => 37, 2 => 1035);
// $_POST array
$_POST  =   array(1,'mystatusmessage1');
// Jump to the end of array
end($array);
// Merge the post with original array
$newArr =   array_merge($array,$_POST);
// Impode
echo implode(",",$newArr);

Repeat with other array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.