0

I want to have a $debugger[] array to debug my php code. I want to display the values stored in this array to the javascript console log. I made a simple function to add elements to the $debugger[] array. [PROBLEM] Unfortunately, anything I pass to the function is not being added to the array, but if I add values to the array OUTSIDE of the function, the array accepts those values. Here is a small snippit of code that is not working. What do I need to change?

`

[ABOVE PHP]
$debugger = [];
function addToDebugger($p_value)
    {
    $debugger[] = $p_value;
    }
addToDebugger('testa');
addToDebugger("testb");
addToDebugger("testc");
addToDebugger("testd");
    $debugger[] = 'test2';
    $debugger[] = 'test3';
.
.
.
[BOTTOM IN JAVASCRIPT TAG]


console.log("DEBUGGING PHP [BEGINNING]");
<?PHP
//debugging php
?>
console.log('<?PHP echo count($debugger); ?>');
<?PHP
for($i=0;$i<count($debugger);$i++)
    {
    ?>
    console.log('<?PHP echo $debugger[$i]; ?>');
    <?PHP
    }
?>
console.log("DEBUGGING PHP [ENDING]");


`

Thank you for your help

When trying the code above [test2, test3] get added but [testa, testb, testc, testd] do not get added.

Bryan
  • 123
  • 7

0 Answers0