Forum Moderators: coopster
foreach($result_array as $row) {
switch($row[0]) {
case 'LP': $row[] = "12"; break;
case 'LW': $row[] = "34"; break;
case 'YL': $row[] = "56"; break;
case 'MS': $row[] = "78"; break;
default: $row[] = $row[0]; break;
}
}
print_r($result_array);
foreach($result_array as $row) {
switch($row[0]) {
case 'LP': $row[] = "12"; break;
case 'LW': $row[] = "34"; break;
case 'YL': $row[] = "56"; break;
case 'MS': $row[] = "78"; break;
default: $row[] = $row[0]; break;
}
}
print_r($result_array);
I found a solution, but I am not sure whether it's the best possible, as some websites mentioned drawbacks.
foreach($result_array as &$row)
unset($row)afterwards - outside of your loop.
foreach($result_array as &$row)
As of PHP 5.3.0, you will get a warning saying that "call-time pass-by-reference" is deprecated when you use & in foo(&$a);.
(I think that's the syntax. I have honestly never used this)function something(&$some_var) {
$some_var = 'foo';
}
something($bar);
echo $bar;
rocknbil: In your original example, don't you want continue instead of break? That should have worked. Continue = go to next iteration, break = break out of the loop completely.
Matthew1980: function MyFunction(Array &$variable){//<<Function only expects a certain type to be passed into it
I think this is used as a less memory intensive way of accessing variable data, idea being is that if you have a large application you can use it as a pointer, kinda like * in C if memory calls. So that you don't need to pass the entire memory cluster into the for each, you can just do it by reference.