-1

first, i get the table value with jquery plugin name is tableToJson. and the type is json object. then i converting the json object with JSON.stringify. and the result show like this:

Array
(
[0] => stdClass Object
    (
        [Kode] => 450
        [Nama Menu] => ES JAHE/null
        [Sat] => TKO
        [Qty] => 1
        [Harga] => 25000
        [Jml Harga] => 25000
    )

[1] => stdClass Object
    (
        [Kode] => 310
        [Nama Menu] => NASI/null
        [Sat] => CTG
        [Qty] => 2
        [Harga] => 20000
        [Jml Harga] => 40000
    )

)

but i want the result is :

Array
(
[0](
        [Kode] => 450
        [Menu] => ES JAHE/null
        [Sat] => TKO
        [Qty] => 1
        [Harga] => 25000
        [price] => 25000
    )

[1](
        [Kode] => 310
        [Menu] => NASI/null
        [Sat] => CTG
        [Qty] => 2
        [Harga] => 20000
        [price] => 40000
    )

  )

how i'm get the result like that with data type is array without stdclass object.

M. Fahmi Ulul Azmi
  • 90
  • 1
  • 3
  • 15
  • 1
    try this code json_decode(json_encode($array), true); – four Nov 07 '16 at 07:52
  • What is that second code block supposed to be? Those are the same objects. as you're showing in the first block. You just removed the object's type from the output... – Cerbrus Nov 07 '16 at 07:53
  • also http://stackoverflow.com/questions/4345554 and a couple others. Please use the search function before asking questions. Thanks. – Gordon Nov 07 '16 at 08:13
  • This is a good question, which is not answered by the the duplicate, or Gordon's one. I still don't have an answer to it! – NessBird May 23 '19 at 17:22

1 Answers1

1

You can cast the object to an array, the result is an array whose elements are the object's properties:

$resultArray =  (array) $obj;

you can perform this in a loop to get a multi-dimensional array of the StdClass objects you have in an array.

KAD
  • 10,972
  • 4
  • 31
  • 73