Reputation: 1511
What would be the equivalent PHP array structure to create an object with identical properties:
For example... create the object 'columns' below in PHP using json_encode:
jQuery('#example').dataTable( {
"ajaxSource": "sources/objects.txt",
"columns": [
{ "data": "engine" },
{ "data": "browser" },
{ "data": "platform" },
{ "data": "version" },
{ "data": "grade" }
]
} );
(I am trying to build a dynamic datatable and define the columns in the source JSON.
Upvotes: 1
Views: 224
Reputation: 1621
You could use an ArrayObject
new ArrayObject([
"ajaxSource" => "...",
"columns" => [
new ArrayObject(['data' => 'engine']),
new ArrayObject(['data' => 'browser']),
new ArrayObject(['data' => 'etc'])
]
]);
if you want to assemble this you need to store the objects inside an array like
$columns = [];
for(...) {
$columns[] = new ArrayObject(['data' => 'etc']);
}
Have a look at http://php.net/manual/de/arrayobject.construct.php
Upvotes: 1