目前分類:Codecademy (8)

瀏覽方式: 標題列表 簡短摘要

1.if迴圈

EX1:

if 8 > 9:
    print "I don't get printed!"
elif 8 < 9:
    print "I get printed!"
else:
    print "I also don't get printed!"

 

注意!在if、elif、else後面都有":"號

EX2:

def greater_less_equal_5(answer):
if answer>5:
return 1
elif answer<5:
return -1

Joseph Lin 發表在 痞客邦 留言(0) 人氣()

1.註解

一行註解使用#

 

一個區塊註解

EX:

"""

comment

"""

2.變數

直接打變數名稱,不需要宣告

Joseph Lin 發表在 痞客邦 留言(0) 人氣()

1.關聯陣列Associatively Array

關聯陣列Associatively Array,又稱Map,他是將陣列內之key依照以下之方式指定value之陣列

'key' => value

可以指定所有陣列內所有key之value,而不另外設一相應陣列

EX:

<?php
// This is an array using integers as the indices.
// Add 'BMW' as the last element in the array!
$car = array(2012, 'blue', 5, "BMW");

// This is an associative array.
// Add the make => 'BMW' key/value pair!

Joseph Lin 發表在 痞客邦 留言(0) 人氣()

1.PHP裡的Object有

class Classname {

}

或是

$obj1 = new Classname();

此兩種方式建立,後者稱為constructor

第一種Object建立方式範例

class Classname {
  public $prop1 = true;
  public $prop2;
  public $prop3;
  public $prop4;
}
  $obj1 = new Classname();
  $obj2 = new Classname();
  echo $obj1->prop1;

 constructor亦可以用method(在class中的function)來運用

EX:

class Classname {
  public $prop1 = true;
  public $prop2;
  public $prop3;
  public $prop4;
  public  function functionName($prop2, $prop3, $prop4) {
    $this->prop2 = $prop2;
    $this->prop3 = $prop3;
    $this->prop4 = $prop4;
  }
}
  $obj1 = new Classname("tired", "54321", 54321);
  $obj2 = new Classname("your", "name", 99);
  echo $obj1->prop1;
  echo $obj2->prop4;

 

 2.__construct(){}

construct是PHP內建method,當新的Object以new來新增時會用到

EX:

Joseph Lin 發表在 痞客邦 留言(0) 人氣()

1.strlen()

計算字串共有幾個字(含空格、標點符號)

EX:

<?php
  // get the length of a string and
  // print it to the screen
  $length = strlen("david");
  print $length;//5
?>

 

2.substr()

從字串中提取部分的字

EX:

$myname = "David";

// you can manipulate strings easily
// with built-in funtions too
$partial = substr($myname, 0, 3);
print $partial;
// prints "dav"

 

substr(目標, 目標內的第幾個字串[從0開始], 字串要擷取幾個字)

 

文章標籤

Joseph Lin 發表在 痞客邦 留言(0) 人氣()

  • May 19 Mon 2014 14:26
  • PHP

1.

<?php

echo "string"

?>

 

PHP以<?php... codecodecode... ?>為前後引號

 

echo將後面的code顯示於網頁上

文章標籤

Joseph Lin 發表在 痞客邦 留言(0) 人氣()

document.write("string");

在預覽視窗顯現string(3/15)

"string".length;

string的字數(4/15)

 

main.js

-------------------------------------------------------------------------------------------------------------------------------------------------

var red = [0, 100, 63];
var orange = [40, 100, 60];
var green = [75, 100, 40];

Joseph Lin 發表在 痞客邦 留言(0) 人氣()

$(this).selectable();

所選element可以以滑鼠點擊(9/14)

$(this).sortable();

使所選element可用滑鼠拖曳來更換順序(10/14)


文章標籤

Joseph Lin 發表在 痞客邦 留言(0) 人氣()