Answer the question
In order to leave comments, you need to log in
Sum two elements of two different arrays and put the result into a variable in php?
I have two arrays with elements:
$array[1] // this is where the number 10 is stored, when I echo the result it shows 10
$array2[1] // this is where the number 20 is stored, when I echo the result it shows 20
My code , like:
$summa = $array[1] + $array2[1]; // - shows the result 10
If before $summa, assign array1 to a variable and array2 to another variable and add them to $summa - the result will be generally 00 ( echo "$summa"; // shows 0 )
These values are entered into arrays through code execution :
get_file_contents...
preg_match
Maybe that's why I can't add them together? Maybe they are not stored in numeric data, but as a string?
Answer the question
In order to leave comments, you need to log in
$array2[1] // the number 20 is stored here, when I echo the result it shows 10
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question