Answer the question
In order to leave comments, you need to log in
Simple declaration of data structures in php
Good afternoon!
A question for those who know and understand. Maybe some of you are familiar with js and know how easy it is to declare arrays, objects and fill them with data. So the question is ripening - is there a similar possibility for php? There is an idea with json_decode(), but it's way too slow :(
var _a={a:{a:'a', b:'b', c:'c'}, b:[1, 2, 3, 4]}
Answer the question
In order to leave comments, you need to log in
Sorry, maybe I didn't understand the question:
$MyObject = array(
'one' =>
array (
'some' => 12,
'other' => 13.5,
'another' => true,
'complex' => array (1,2,3,4,5),
'simple' => 'value',
'object' => new MyObjectType(42)
),
'two' =>
array (
'ITthinkYouGotIt' => 'right?'
)
);
Something like this appeared in 5.4k
. New Syntax
- Short array syntax in 5.4.0
$a = [1, 2, 3, 4];
$a = ['one' => 1, 'two' => 2, 'three' => 3, 'four' => 4];
$a = ['one' => 1, 2, 'three' => 3, 4];
I don't see any problem. Use array('key'=>'value'), for objects you can use transformation (object)array('key'=>'value'). Yes, write a little more, but not critical.
var myArr = new Array();
myArr ["str1"] = "1111";
myArr ["str2"] = "2222";
myArr .push("33");
Comrades, if you do not read the question and look at the keywords, please do not answer!
agree that writing {a:{a:'a', b:'b', c:'c'}, b:[1, 2, 3, 4]} is much simpler and faster than all the options you suggested above.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question