Hmm... this is really strange. This happened in my attempts to directly change a single dimensional array into a multidimensional one...
<?php
$members[] = "a string here";
$members[] = "and yet another here";
foreach($members as $key => $value)
{
$members[$key]["orig"] = $value;
}
print($members[1]["orig"]);
// prints "a", always the first letter of the string
?>
I realized this code was accessing my $members[] array directly (duh... 😛), so I did this and it worked:
<?php
$members[] = "a string here";
$members[] = "and yet another here";
foreach($members as $key => $value)
{
$members[$key] = "";
$members[$key]["orig"] = $value;
}
print($members[1]["orig"]);
// prints "and yet another here"
?>
Does anyone know why the first example prints the first letter, though? This means it was actually instantiating that element, but why was it giving it only one character?
The only reason I could think of was that maybe "orig" was actually evaluating to zero or one or something, but that still doesn't explain how it was giving it only one letter.