How to convert PHP array to a JSON array? -
for example, have next code in json:
{ "tag": "img", "attr": [ { "alt": "text", "src": "url", "void": "true", "all": "true" } ] }
what php code should utilize echo/print
code above? tried this:
$arr = array ( "tag" => "img", $attr = array ( "alt" => "text", "src" => "url", "void" => "true", "all" => "true" ) );
and then:
echo $arr = json_encode($arr);
but error. ideas?
your array declaration wrong. should be:
$arr = array ( "tag" => "img", "attr" => array ( "alt" => "text", "src" => "url", "void" => "true", "all" => "true" ) );
php arrays json
No comments:
Post a Comment