this question has answer here:
my array is:
{ "data":"data:image/png;base64,ivborw0kggoaaaansuheugaaayaaaajycayaaacadojwaaagaeleq…accccaaaiiiicavwieip760zoccccaaaiiiiaaaoes+p992sgq2e6rdwaaaabjru5erkjggg==", "name":"splash.png", "imageoriginalwidth":1024, "imageoriginalheight":768, "imagewidth":1969, "imageheight":1477, "width":800, "height":600, "left":-585, "top":-406 }
and have 2 variables:
$image_data = $array['data']; $image_name = $array['name'];
both of these variables return undefined
am missing obvious?
first off, it's important note not array, it's object definition.
an array can defined as:
[ "data:image/png;base64,ivborw0kggoaaaansuheugaaayaaaajycayaaacadojwaaagaeleq…accccaaaiiiicavwieip760zoccccaaaiiiiaaaoes+p992sgq2e6rdwaaaabjru5erkjggg==", "splash.png", 1024, 768, 1969, 1477, 800, 600, -585, -406 ]
which doesn't keys, "data":
(which can expressed data:
) seems want access values key, want is:
var data, name, myobject; // note: not "quote" object keys under normal circumstances. myobject = { data:"data:image/png;base64,ivborw0kggoaaaansuheugaaayaaaajycayaaacadojwaaagaeleq…accccaaaiiiicavwieip760zoccccaaaiiiiaaaoes+p992sgq2e6rdwaaaabjru5erkjggg==", name:"splash.png", imageoriginalwidth:1024, imageoriginalheight:768, imagewidth:1969, imageheight:1477, width:800, height:600, left:-585, top:-406 } data = myobject["data"]; // don't usuaully use name = myobject["name"]; // style, although works. // // it's reserved // dynamic access. // // i.e. make string match keyname.
however, correct should use dot syntax access object key.
data = myobject.data; name = myobject.name;
i hope has cleared things little you.
on side note not use names $array
. first don't use $
prefix normal variables, isn't php or basic.
secondly, when have object, want named useful / meaningful / memorable. (naming things hard!)
when name things properly, other people can read , understand code, , after heavy weekend on town, can you.