php - array to string conversion return error of stdClass -


    if($stmt->execute()){         $user = $stmt->get_result();         while ($obj = $user->fetch_object()) {              $result[] = $obj;         }     }  $result1encoded = json_encode($result); echo $result1encoded; // [{"uid":"1","firstname":"john"}] 

i used implode :

    echo $result1encoded = implode(' ',$result1); // expecting '[{"uid":"1","firstname":"john"}]' 

but says

object of class stdclass not converted string  

you can use array_map("json_encode", $your_array) first convert each element of array string, , use implode glue together.

see https://eval.in/141541

<?php  $a = array();  $a[0]  = new stdclass(); $a[0]->uid = "1"; $a[0]->firstname = "john";  $a[1]  = new stdclass(); $a[1]->uid = "2"; $a[1]->firstname = "albert";  $b = array_map("json_encode", $a); echo implode(' ', $b);  ?> 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -