Return jSON to a variable

0

I have a PHP code that creates a jSON:

<?php

$array3 = array(array('0,1300', 'Thalita', 'Nicole'));


echo json_encode($array3);
?>

And I have another code that is in jQuery that forms a graphic, with the following settings:

var d1 = [
        [0, 1450], [1, 1300], [2, 1600], [3, 1900], [4, 2100], [5, 2500], [6, 2200], [7, 2000], [8, 1950], [9, 1900], [10, 2000], [11, 2120]
    ];

I need to do is get the jSON return that I created with PHP and play on that d1 variable to form the chart correctly. And not forgetting that you have to return with two [[]] as the variable d1 above.

    
asked by anonymous 13.07.2014 / 20:49

1 answer

1

If so, you can create this array in PHP as you are creating it, and send it through a function:

<?PHP
    $array3 = array(array('0,1300', 'Thalita', 'Nicole'));
    $jsonArr=json_encode($array3);
?>
<script>
    function makeGraph(data){
        d1=data;
        //manipulação de array dentro do javascript...
    }
</script>
<body onload="javascript:makeGraph(<?= $jsonArr ?>);">

The onload action in the body was just to demonstrate the method call, you can put the code inside of it in any HTML script or action.

    
13.07.2014 / 21:04