I am finding that altering and affecting values in elements in
multidimensional arrays is a huge pain in the ass. I cannot seem to find a
consistent way to assign values to arrays. Foreach would clearly be the most
efficient way to do it, but it only works on a copy of the original array
and not the original (which is counter intuitive in my estimation). Using
each doesn't work consistently either. Not only that, it's unduly complex
for multidimensional arrays that are more than 3 dimensions. For example,
here's an array $data:
0 => Array (8)
id => 8
name => test entry3 3 2fsdfsdfs sdf sdf
address => empty
city => empty
state => 66
closingdate => empty
loanamount => 0
date => empty
1 => Array (8)
id => 9
name => test entry 2
address => empty
city => empty
state => 66
closingdate => empty
loanamount => 0
date => empty
2 => Array (8)
id => 10
name => empty
address => empty
city => empty
state => 66
closingdate => empty
loanamount => 0
date => empty
I would like to iterate through this array and add an element to each called
url which will be assigned based on a function of id. In pseudocode:
foreach ($data as $array) {
$array['url'] = SomeCoolFunction("$array['id']");
}
How can I do this? Assigning values to elements and working with existing
arrays in Perl is extremely easy. This appears to be a weakness in the
design of PHP. Thoughts?
TIA
GN