1

I have a json_encode element and i have to implode it like that

<?php
$user = json_decode($var);
$fetch_array = implode(",", $user);
?>

with the debug print_f the array result like that

Array( [0] => stdClass Object ( [id] => 4 [name] => Elis ) 
       [1] => stdClass Object ( [id] => 5 [name] => Eilbert ))1

it result a error: Object of class stdClass could not be converted to string

My goal is use this json array with the statment SELECT IN on mysql,

SELECT * FROM table WHERE field IN $user

I tought that i have to implode it. if I delete the function implode it show me (array,array)

How can i do that?

1
  • Show please source json string and result you expect Commented Oct 1, 2013 at 14:00

1 Answer 1

5

json_decode returns an object by default. In your case, you need an array. Add 2nd param as true as below:

json_decode($var, true);
Sign up to request clarification or add additional context in comments.

4 Comments

if i put the second parameter true it show me this error: Array to string conversion
Why do you have implode.? Its not needed. json_decode returns an array.
My goal is use this json array with the statment SELECT IN on mysql, I tought that i have to implode it. if I delete the function implode it show me (array,array)
sorry man. You need implode to convert array to comma delimited string. Then you can use inside mysql query.

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.