×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Maria Dan
Added: Mar 16, 2021 4:31 PM
Modified: Mar 18, 2021 4:37 PM
Views: 4809
Tags: array foreach
  1. $arr = [
  2.     'name1' => 'Alex',
  3.     'name2' => 'Misha',
  4.     'name3' => 'Anna'
  5.    
  6. ];
  7.  
  8. foreach($arr as $key => $value) {
  9.     echo "ключ $key  значение $value \n";
  10. }
  11.  
  12.   print_r($arr);
  13.  
  14. #вывод двумрного массива ->
  15. $pets = [
  16.       'dogs' => [
  17.               "german shepherd", "beagle", "samoyed"
  18.       ],
  19.       'cats' => ["bengal", "siamese", "russian shorthair", "maine coon"]
  20.   ];
  21.   $startUl = "<ul>";
  22.   $endUl = "<ul>";
  23.   $list = "";
  24.   foreach($pets as $key => $value) {
  25.       foreach ($value as $key2 => $value2) {
  26.           $list = $list."<li>$value2</li>";
  27.       }
  28.   }
  29.   $list = $startUl.$list.$endUl;
  30.   echo $list;
  31.   #<-
  32.  
  33.  
  34.   $timesTwo = array_map(function($num){
  35.       return $num * 2;
  36.   }, $numbers);
  37.  
  38.  
  39.