I had trouble to call the 2nd dimension data of the array, I have an array like this
(13) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {azimuth: 1.9834929332749562, altitude: -0.0009456257895690352, zenith: 1.5717419525844656, azimuthDegrees: 113.6457737706788, altitudeDegrees: -0.05418036674103183, …}
1: {azimuth: 1.9625993875035166, altitude: 0.2381641039831701, zenith: 1.3326322228117264, azimuthDegrees: 112.4486617789119, altitudeDegrees: 13.645797989750525, …}
2: {azimuth: 1.9670438426767658, altitude: 0.4781320008138626, zenith: 1.092664325981034, azimuthDegrees: 112.70331030257417, altitudeDegrees: 27.394945696779967, …}
3: {azimuth: 2.0056409208258157, altitude: 0.716028155591109, zenith: 0.8547681712037876, azimuthDegrees: 114.91475998205134, altitudeDegrees: 41.02539132790719, …}
4: {azimuth: 2.106117875144968, altitude: 0.9464893499017506, zenith: 0.624306976893146, azimuthDegrees: 120.67166540286752, altitudeDegrees: 54.229845103451325, …}
5: {azimuth: 2.352774172235539, altitude: 1.1542514926942995, zenith: 0.41654483410059706, azimuthDegrees: 134.8040302164822, altitudeDegrees: 66.13373902805874, …}
6: {azimuth: 2.9582193797984337, altitude: 1.2825445688422454, zenith: 0.2882517579526511, azimuthDegrees: 169.4934853362582, altitudeDegrees: 73.48439083208653, …}
7: {azimuth: 3.727387198651306, altitude: 1.2258827648993766, zenith: 0.3449135618955199, azimuthDegrees: 213.5635550938108, altitudeDegrees: 70.23790860656241, …}
8: {azimuth: 4.097477963055694, altitude: 1.040743662815431, zenith: 0.5300526639794656, azimuthDegrees: 234.76819393095275, altitudeDegrees: 59.630219434310625, …}
9: {azimuth: 4.244625795743045, altitude: 0.8170110513103618, zenith: 0.7537852754845348, azimuthDegrees: 243.19914370843512, altitudeDegrees: 46.81128505563008, …}
10: {azimuth: 4.304659041507528, altitude: 0.5813792398726065, zenith: 0.98941708692229, azimuthDegrees: 246.6387953212116, altitudeDegrees: 33.31057674122426, …}
11: {azimuth: 4.322058816246406, altitude: 0.34187533384813323, zenith: 1.2289209929467633, azimuthDegrees: 247.63572897822766, altitudeDegrees: 19.588013749124052, …}
12: {azimuth: 4.311693172055207, altitude: 0.1020810862683183, zenith: 1.4687152405265782, azimuthDegrees: 247.04182131413768, altitudeDegrees: 5.848815411285501, …}length: 13[[Prototype]]: Array(0)
I got it from Ajax call using JSON.stringify like below
var sunarray = [];
for(){
doSomething();
sunarray.push();
}
var solararray = JSON.stringify(sunarray);
sendDatathroughtAJAX();
in the server, I was able to call the first dimension by
$sun = json_decode($_POST['arrayraw']);
$data = pg_escape_string(anotherdata]);
echo json_encode($sun[1]);
//vv result in console.log vv
:{
"azimuth": 1.9625993875035166,
"altitude": 0.2381641039831701,
"zenith": 1.3326322228117264,
"azimuthDegrees": 112.4486617789119,
"altitudeDegrees": 13.645797989750525,
"zenithDegrees": 76.35420201024948,
"declination": -0.4090977792339249,
"date": "2024-12-21T23:29:51.187Z"
}
I have trouble calling the 2nd dimension data by
echo json_encode($sun[1][azimuth]);
echo json_encode($sun[1]['azimuth']);
The only difference I got compared to the other people’s questions is that I don’t have any quotation marks for the key and value of the array.
Does anybody know how to call this 2nd dimension array data?