PHP array to javascript array

前端 未结 4 1041
逝去的感伤
逝去的感伤 2021-01-29 00:47

Suppose, I have this array in php

$cities=array(
    \"Caracas\"=>array(
        \"air\"=>array(
            \"4\",\"3-5 Working Days\",\"Saturday\"
               


        
4条回答
  •  自闭症患者
    2021-01-29 01:03

    PHP

    echo json_encode($cities);
    

    jQuery

    $.getJSON("php_file.php",function(data) {
        // "data" is the echoed encoded array from the php file.
    
        // "array"."city name"."'air' or 'sea'"."number value that is in the PHP file"
        data.Caracas.air.4 // this is how you access the data inside the array
    });
    

提交回复
热议问题