I have 2 different but kind of the same function. One is made in php, the other is made in javascript. They both look the same to me. Yet they both do different things. I want to know why. Is it because these functions behave differently in both languages or is it they way they work with variables?
I have one file saved as test.php. It looks like this:
$test= [5,6,7,8];
function testing(){
$test = [1,2,3,4,5];
echo 'the function worked <br>';
}
testing();
var_dump($test);
It gives me back:
the function worked
array(4) { [0]=> int(5) [1]=> int(6) [2]=> int(7) [3]=> int(8) }
Now for about the same function in javascript. This is saved as test.html.
<script>
var test= [5,6,7,8];
function testing(){
test = [1,2,3,4,5];
}
testing();
console.log(test);
</script>
In my console, I see my array is [1,2,3,4,5]
So my array in php is [5,6,7,8].
My array in javascript is [1,2,3,4,5].
Why does it work different?