I have defined an array in php
$letters = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","W","V","X","Y","Z");
Then I try to assign the array to a new variable, that is also an array:
$new_array = array();
$new_array = $letters;
But it's not working, why?
You can just do
$new_array = $letters;
You don't have to specify the type because it is implied.
You do not need to create an empty array. Your second assignment is actually correct. The nice trick is to dump content of a variable using var_dump() to see its actual value.
Try this:
$letters = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","W","V","X","Y","Z");
$new_array = $letters;
var_dump($new_array);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With