I'm using an array in php that I want to use in javascript with a specific index
valor = 1;
var arrayreceitas = \<?php echo json_encode($array_seccao\[ \*\*it is possible to use this value here\*\* valor\]\[0\]); ?\>;
}
I'm using an array in php that I want to use in javascript with a specific index
valor = 1;
var arrayreceitas = \<?php echo json_encode($array_seccao\[ \*\*it is possible to use this value here\*\* valor\]\[0\]); ?\>;
}
JavaScript executes later, after PHP has produced the page (and JS script). So just let PHP produce the whole array in the JS script and add the code for JS to grab the element at the intended index:
valor = 1;
var arrayreceitas = <?= json_encode(array_column($array_seccao, 0)); ?>[valor];
Obviously, this is only useful when the JS script will have a dynamically determined valor
. If it is a constant like here, then PHP would just apply that index first and JS would no longer need valor = 1
.