4) 配列

  ごく普通のサンプル



  
<?
$a = array(2,4,6,8,10);

for( $i = 0; $i < count( $a ); $i++ ) {
	print $a[$i] . "<BR>";
}
?>

  

count --> http://www.php.net/manual/ja/function.count.php

  追加方式



  
<?
$a[] = 2;
$a[] = 4;
$a[] = 6;
$a[] = 8;
$a[] = 10;

for( $i = 0; $i < count( $a ); $i++ ) {
	print $a[$i] . "<BR>";
}

?>

  

  連想配列

  
<?
// ---------------------------------------------------------------
//  定義
// ---------------------------------------------------------------
$rect = array( 'top'	=> 0
            , 'left'	=> 0
            , 'right'	=> 800
            , 'bottom'	=> 600
            );

// ---------------------------------------------------------------
//  表示1
// ---------------------------------------------------------------
foreach( $rect as $key => $value ) {
	print "$key はインデックスで $rect[$key] は値です<br>";
}

// ---------------------------------------------------------------
//  2行改行
// ---------------------------------------------------------------
print str_repeat( "<br>", 2 );

// ---------------------------------------------------------------
//  表示2
// ---------------------------------------------------------------
foreach( $rect as $key => $value ) {
	print "$key はインデックスで $value は値です<br>";
}

?>

  

str_repeat --> http://www.php.net/manual/ja/function.str-repeat.php

  配列を空にする

  
<?

print count( $rect ) . "<br>";

$rect = array( 'top'	=> 0
            , 'left'	=> 0
            , 'right'	=> 800
            , 'bottom'	=> 600
            );

print count( $rect ) . "<br>";

// ---------------------------------------------------------------
// 空にする
// ---------------------------------------------------------------
$rect = array();

print count( $rect ) . "<br>";

?>

  











   SQLの窓    create:2003/01/07  update:2014/09/07   管理者用(要ログイン)





フリーフォントWEBサービス

SQLの窓WEBサービス

SQLの窓フリーソフト

写真素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ