ph4x35ccb

Array

Feb 24th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.47 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title></title>
  5. </head>
  6. <body>
  7.     <h1><font color='blue'>Arrays associativos sintaxe alternativa e muiltidimensionais</font></h1><br><br>
  8. <?php
  9. //array com contrutor php
  10. $cursos = ['PHP','Java','C#','Python'];
  11. var_dump($cursos); //imprime o aray
  12. echo "<br><br>";
  13. //array associativos
  14. $filmes = ['The Lord of Rings' => 2002, 'Hobbit' => 2012];
  15. var_dump($filmes);
  16. echo "<br><br>";
  17. echo $filmes['Hobbit']; //imprimira 2012
  18. echo'<br><br>';
  19. //sintaxe alternaiva
  20. $curso[] = "PHP";
  21. $curso[] = "HTML5";
  22. $curso[] = "CSS3";
  23. $curso[] = "JavaScript";
  24. $curso[] = "MySQL";
  25. var_dump($curso);
  26. //outro exemplo
  27. //$curso[1] = "PHP";
  28. //$curso[2] = "HTML5";
  29. //$curso[3] = "CSS3";
  30. //$curso[4] = "JavaScript";
  31. //$curso[5] = "MySQL";
  32. //array com valores literais
  33. echo "<br><br>";
  34. $_cursos['primeiro'] = "PHP";
  35. $_cursos[2] = "HTML";
  36. $_cursos['terceiro'] = "CSS3";
  37. $_cursos[4] = "JavaSript";
  38. $_cursos['quinto'] = "MySQL";
  39. var_dump($_cursos);
  40. //colchete [] vasil para adicionar novos valores
  41. $megasena = array(10,13,44,58,43);
  42. //adiciona 33
  43. $megasena[] = 33;
  44. var_dump($megasena);
  45. //array multidimencionais
  46. echo "<br><br>";
  47. $html =[
  48.     'html' =>[
  49.         'head' =>[
  50.             'title',
  51.             'link',
  52.             'script'
  53.         ],
  54.         'body' => [
  55.             'p',
  56.             'h1',
  57.             'div' => [
  58.                 'p',
  59.                 'a'
  60.             ]
  61.         ]
  62.     ]
  63. ];
  64. //print_r e especialmente usada para imprimir array
  65. print_r($html);
  66. //https://www.facebook.com/groups/353340335260087/
  67. //irc.vircio.org #sampa
  68. ?>
  69. </body>
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment