0

Should be a nice easy one today but I can't find the answer anywhere.

I have a multidimensional array. It stores partid and quantity.

$pCombined[] = array ( $newName[$b], $newQty[$b] );

I want to use PHP join as suggested here: Passing an array to a query using a WHERE clause

I need to get more data from mySQL about the parts so I need the list of ids joined up as I don't like the idea of running one SQL query for each row.

I tried to use:

$ids = join(',', $pCombined);

That just gives array, array, array....e.t.c.

I tried a few obvious combinations of square brackets. What I guess I want is...

$ids = join(',', $pCombined[*][0]); (where * is all)

I think I might also be overcomplicating the whole thing and I could use foreach or a for loop and join manually I guess. Its not quite a basic shopping cart but the principals are similar. Any ideas how I can do this or perhaps push me in a different direction. Thanks.

1 Answer 1

1

to combine array elements can use the following

$elemens = array("one","two","there","four")

$exit = implode(',',$elements);

print_r($exit);//one,two,...

I hope you serve

Sign up to request clarification or add additional context in comments.

2 Comments

I don't think this is really what I am after. I need to prepare them for SQL but the original array is multi-dimensional. Imagine $pCombined[x][y] where [x] is rows and [y] is columns. I need to join all the items in column 1.
Thanks for the use of implode though. I used a for loop to collect the column data into a new array and then used $ids = implode(',', $newArray); I'm convinced there must be a way to do this without using a loop to extract the data I want from the multidimensional array though.

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.