I feel like I am losing my mind.
<?php
print_r($roc_option);
?>
prints out this:
Array ( ['class'] => classnew1 ['id'] => idnew1 )
but then, on the next line,
<?php
echo $roc_option['class'];
?>
prints out NOTHING.
Any ideas what is going on?
Context:
This is happening inside a foreach loop.
A similar construction outside the loop, echo $roc_options[0]['class']; provide similarly nothing.
EDIT
Complete context (lots of debugging crud added to keep me sane)
Code
echo "ln1 -- <br>";
print_r(array_values( $roc_options ));
echo "<br><br>ln2 -- <br>";
print_r(array_values( $roc_options[0] ));
echo "<br><br>ln3a -- <br>";
echo $roc_options[0]['class'];
echo "<br><br>ln3b -- <br>";
echo $roc_options[0][0];
foreach ( $roc_options as $roc_option ){
echo "<br>inside foreach <br>";
echo "<br><br>ln4 -- <br>";
print_r($roc_option);
echo "<br><br>ln5 -- <br>";
echo $roc_option[0];
output
ln1 -- Array ( [0] => Array ( ['class'] => classnew1 ['id'] => idnew1 ) )
ln2 -- Array ( [0] => classnew1 [1] => idnew1 )
ln3a --
ln3b --
inside foreach
ln4 -- Array ( ['class'] => classnew1 ['id'] => idnew1 )
ln5 --
I cannot understand why 3a, 3b, and 5 are all empty.
IT GOES ON AND ON
I switched to var_dumps and forced some new names in, just to make sure the form was saving properly...
CODE:
var_dump($roc_options);
echo "ln1 -- <br>";
print_r(array_values( $roc_options ));
echo "<br><br>ln2 -- <br>";
print_r(array_values( $roc_options[0] ));
echo "<br><br>ln3a -- <br>";
var_dump( $roc_options[0]['class'] );
echo "<br><br>ln3b -- <br>";
var_dump( $roc_options[0][0]);
foreach ( $roc_options as $roc_option ){
echo "<br>inside foreach <br>";
echo "<br><br>ln4 -- <br>";
print_r($roc_option);
echo "<br><br>ln5 -- <br>";
var_dump( $roc_option[0] );
echo "<br><br>ln6 -- <br>";
var_dump( $roc_option['class'] );
echo "<br><br>ln7 -- <br>";
var_dump( $roc_option["id"] );
output
array(1) { [0]=> array(2) { ["'class'"]=> string(9) "new class" ["'id'"]=> string(6) "new id" } } ln1 -- Array ( [0] => Array ( ['class'] => new class ['id'] => new id ) )
ln2 -- Array ( [0] => new class [1] => new id )
ln3a -- NULL
ln3b -- NULL inside foreach
ln4 -- Array ( ['class'] => new class ['id'] => new id )
ln5 -- NULL
ln6 -- NULL
ln6 -- NULL
Notice ln4 --- $roc_option is an array with two items. then look at 5-7 I can't get the value out with a numerical index or with a key name, whether in single or double quotes. (When I try without quotes at all, the page doesn't load.)
print_r()outputs are missing things like commas and quotes etc and therefore make no sense. Do not edit the output, put it in your question EXACTLY as it appears without any sensorshipvar_dump($roc_options);before ln1 and edit the results into the answer? Should prove enlightening.