Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Fabian Constien
Added: Nov 5, 2017 1:45 PM
Modified: Dec 12, 2017 4:08 PM
Views: 7
Tags: no tags
  1. $array = array();
  2. $array[] = array('key1' => 'value1a', 'key2' => 'value2a');
  3. $array[] = array('key1' => 'value1b', 'key2' => 'value2b');
  4. foreach ($array as $element) {
  5.     echo $element['key1'];
  6.     echo $element['key2'];
  7. }
  8.  
  9. $array = array();
  10. $array['key1'] = 'value1';
  11. $array['key2'] = 'value2';
  12. foreach ($array as $key => $value) {
  13.     echo $key . ' - ' . $value;
  14. }