0

I have this code:

 if(!empty($item['criteria'])){
            foreach ($item['criteria'] as $item2){
             echo "$item2[description]<br/>".PHP_EOL;
            }
        }

}

Now i need to modify this code to swing open the $item2[description]. I tried it like that:

if(!empty($item['criteria'])){
            foreach ($item['criteria'] as $item2){
             echo '<a href="javascript:toggle(', $item2['id'], ')">'Click</a>
             <div id="', $item2['id'], '" style="display: none">', $item2['description'], '</div>';
            }
        }

}

I think there is a mistake in some signs.

Hertus
  • 147
  • 2
  • 11
  • 2
    You need to learn PHP [string syntax](http://php.net/manual/en/language.types.string.php#language.types.string.syntax.single) – Marc B Jul 08 '16 at 19:11

2 Answers2

1
if(!empty($item['criteria'])){
            foreach ($item['criteria'] as $item2){
             echo '<a href="javascript:toggle('. $item2['id']. ')">Click</a>';
             echo '<div id="'. $item2['id'].'" style="display: none">'. $item2['description'].'</div>';
            }
        }

}

you have some syntactical mistakes check this once

Naisa purushotham
  • 905
  • 10
  • 18
0

Use the . to concat strings

if(!empty($item['criteria'])){
    foreach ($item['criteria'] as $item2){
         echo   '<a href="javascript:toggle('.$item2['id'].')">Click</a>'.
                '<div id="'.$item2['id'].'" style="display: none">'.$item2['description'].'</div>';
    }
}