Saturday, 24 August 2013

Using a variable outside foreach with if statement?

Using a variable outside foreach with if statement?

This code should explain it all..
foreach($this->sections as $k => $section){
$preview = array();
foreach ($section['fields'] as $k => $type) {
$preview[] = $type['type'];
}
if ($preview == 'header_preview'){
echo $preview;
// I will loop content here based on the $section loop NOT the
$type loop
}
}
I just need to get each $section['fields'] then outside that loop, which
again gets a list of all the $section['fields'] then use one of those
field types to create an if statement. The above is non working, I will
show you working code here.
foreach($this->sections as $k => $section){
foreach ($section['fields'] as $k => $type) {
if ($type['type'] == 'header_preview'){
//I work but im in a nested loop I need out
}
}
}
I hope this makes sense...

No comments:

Post a Comment