Answer the question
In order to leave comments, you need to log in
Php - How does an associative array happen?
I started listening to video tutorials on PHP 7 here, and in one of the lessons they said that if you take two ordinary arrays and combine them, you get an associative array.
I was wondering how php would behave if the number of elements in the two arrays were different...
I wrote the following code:
$f1=["Jon","Stas","Fill"];
$f2=["Anna","Jein"];
$f=$f1+$f2;
for ($i=0; $i < count($f); $i++) {
echo "$i --> $f[$i]<br>";
}
echo "<br>";
echo "--> $f['Jon']";
echo "<br>";
foreach ($f as $k => $v) {
echo "$k -- $v<br>";
}
Answer the question
In order to leave comments, you need to log in
It didn't show up because you have an error
echo "--> $f['key']"; echo
"--> ".$f['key'];
$f=$f1+$f2 is not nonsense, the operator has been working like this for a long time ... The same as the merge ...
P.S.
In your link, the first line is also nonsense)?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question