php - Added Array Value to New Array: After var_dump Value Disappears -
I am trying to add an array value to a new array like this:
$ client name [] = $ cname ['name'];
If I use var_dump ($ cname ['name']);
Then everything looks fine, but if i var_dump ($ clientname);
I expect to see the same thing, but I do not feel like I did var_dump ($ cname);
Here's the full code:
foreach ($ clientname $ customer) {foreach ($ client $ cname) {var_dump ($ cname ['name ']); $ Client name [] = $ cname ['name']; Var_dump ($ CLIENTNAME); }}
I had to foreground due to that array structure, obviously var_dump ($ cname ['name']);
Repeats is as expected for the amount of $ Cnames
my $ customer name
to $ cname
So, the arrays you are getting through, are you adding your values too?
In PHP, internally, it copies the array from which it is through the loop. So if you dump the array after foreach'es, then you will see the new value in it.
Why are you adding those values to the same array? Can it be more convenient to create a new array and add it?
In this way PHP works in the example, but if you are trying to solve the problem, then there are better ways to solve it.
Comments
Post a Comment