javascript Array 索引 僅能用數值型態,物件的索引才能用字串型態的。

From: http://stackoverflow.com/questions/9526860/why-does-a-string-index-in-a-javascript-array-not-increase-the-length-size

Javascript arrays cannot have “string indexes". A Javascript Array is exclusively numerically indexed. When you set a “string index", you’re setting a property of the object. These are equivalent:

array.a = ‘foo’;
array[‘a’] = ‘foo’;

Those properties are not part of the “data storage" of the array.

If you want “associative arrays", you need to use an object:

var obj = {};
obj[‘a’] = ‘foo’;

Maybe the simplest visualization is using the literal notation instead of new Array:

// numerically indexed Array
var array = [‘foo’, ‘bar’, ‘baz’];

// associative Object
var dict = { foo : 42, bar : ‘baz’ };

廣告

重設 mysql table auto_increment 初值

出至:http://ariejan.net/2007/11/30/mysql-reset-the-auto-increment-value-of-a-table/

MySQL: (Re)set the auto-increment value of a table
Written by Ariejan de Vroom on 30 November 2007.

via Ad Packs
Sometimes it’s necessary to set the starting point of a MySQL auto-increment value.

Normally, MySQL starts auto-incrementing at 1. But let’s say you want to start at 10.000, because you want at least a five figure number. You can use the following query to set the MySQL auto-index:

ALTER TABLE some_table AUTO_INCREMENT=10000

If you want to delete all records from your table and restart auto-index at 1, you might be tempted to run a DELETE query, followed by the above example, setting the auto increment value to 1. There is a shortcut, however:

TRUNCATE TABLE some_table

This will basically reset the table, deleting all data and resetting the auto increment index. Do not that the truncate command is a hard-reset option. For instance, any triggers “ON DELETE” will not be fired when using truncate.

apache 設定 default index.php 為 DirectoryIndex page

apache 設定 default index.php 為 DirectoryIndex page

有兩種作法:
1. 在該目錄下建立 .htaccess 檔案並在檔案中插入「DirectoryIndex index.php」字串。

The simplest way to accomplish this..
Create a .htaccess file in your web root.
Add the line…

DirectoryIndex index.php

2. 在 apache 設定檔「httpd.conf」的修改指定目錄預設索引頁值。
<Directory /myapp>
DirectoryIndex index.php
</Directory>

Howto: Javascript Array Auto Index(push or array.length)

在記憶中php 把物件加入陣列時,可以自動產生Index。

語法如下:

myArray[]="foo";
myArray[]=bar;

但是想拿同樣的方法用在Javascript上卻行不通。想要讓Javascript的陣列可以自動產生索引值,可以透過下面這兩項方法達成。
繼續閱讀