본문 바로가기
Coding/WebApp

배열

by 그냥그렇듯이 2017. 8. 24.
반응형

모든 저작권은 <생활코딩>의 생산자인 <egoing>님에게 있습니다.

문제시, 비공개로 전환하겠습니다.


<배열>

Array

C의 array[1][1];와 같다.

만들어진 배열을 변수에 담는다.

배열의 순서는 0부터 시작한다.

 JavaScript

 PHP

 list = newArray("one", "two", "three");

list[0];

 $list = array("one","two","three");

$list[0];

 <!DOCTYPE html>

<html>

<head>

     <meta charset="utf-8">

</head>

<body>

  <h1>JavaScript</h1>

  <script>

    list = new Array("one", "two", "three");

    document.write(list[2]);

    document.write(list.length);


  </script>


  <h1>php</h1>

  <?php

    $list = array("one", "two", "three");

    echo $list[2];

    echo count($list);

  ?>

</body>

</html>

 


<배열과 반복문>

배열+반복문 = 바늘+실

JavaScript

 PHP

 list = new Arrya("one", "two", "three");

i=0;

while(i<list.length){

document.write(list[i]);

i=i+1;

}

 $list = array("one", "two", "three");

$i=0;

while(i<count($list)){

echo $list[i];

$i=$i+1;

}

 <!DOCTYPE html>

<html>

<head>

     <meta charset="utf-8">

</head>

<body>

  <h1>JavaScript</h1>

  <ul>

  <script>

    list = new Array("최진혁", "최유빈", "한이람", "한이은", "이고잉");

    i = 0;

    while(i < list.length){

      document.write("<li>"+list[i]+"</li>");

      i = i + 1;

    }

  </script>

  </ul>

 

  <h1>php</h1>

  <ul>

  <?php

    $list = array("최진혁", "최유빈", "한이람", "한이은");

    $i = 0;

    while($i < count($list)){

      echo "<li>".$list[$i]."</li>";

      $i = $i + 1;

    }

  ?>

  </ul>

</body>

</html>

댓글