yii_king
(Micho23)
October 11, 2012, 12:05pm
1
I have an array which contains data retrieved from a database table.
I know that I can retrieve the values by a normal foreach loop like this which is then going through the array row by row.
foreach ($arr as $val) {
echo $val->date.<br/>;
echo $val->hour1.<br/>;
echo $val->hour2.<br/>;
}
However, I am using a jquery plugin which requires me to print out the values vertically instead. I’m trying this:
// Columns are 2012-10-11 and 2012-10-12 and the data below goes straight under each column
foreach ($arr as $val) {
$date = $val->date;
foreach ($date as $v) {
echo ‘[’.$v->hour1.’, ‘.$v->hour1.’],’; // Each day shows hour 1
echo ‘[’.$v->hour2.’, ‘.$v->hour2.’],’; // Each day shows hour 2
}
}
This is not working. Any ideas?
Keith
(Kburton)
October 11, 2012, 2:40pm
2
I’m not quite sure what you’re asking and it’s not clear from the code how your data is structured or what you’re trying to do. Can you try to explain it again?
mentel
(Yii)
October 11, 2012, 3:04pm
3
You can try something similar to this:
foreach (array('date', 'hour1', 'hour2') as $field) {
foreach ($arr as $val) {
echo $val->$field;
}
}
yii_king
(Micho23)
October 11, 2012, 10:06pm
4
You can try something similar to this:
foreach (array('date', 'hour1', 'hour2') as $field) {
foreach ($arr as $val) {
echo $val->$field;
}
}
Thank you so much Rodrigo. That was exactly what I needed.