How do you define an empty array for objects?

by 2 replies
3
What I'm trying to do is escape each element of an array then store it in a new array as objects, this is my code:

But it will prompt me this error saying:

Can somebody please tell me what I'm doing wrong? Thanks guys
#programming #array #define #empty #objects
  • It should be

    <?php
    $myarray = array(array data);
    $myobj = new stdClass;
    foreach ($myarray as $key => $data) {
    $myobj->$key = $data;
    }
    ?>
    • [ 1 ] Thanks
    • [1] reply
    • Just follow this code. This is correct.

Next Topics on Trending Feed