php數組圖片
是隨機顯示的啊,我測試沒有問題啊
2. php數組的例子
php 中的數組類型有非常多的用途,因此這里有一些例子展示數組的完整威力。
<?php// this$a = array( 'color' => 'red', 'taste' => 'sweet', 'shape' => 'round', 'name' => 'apple', 4 // key will be 0 );// is completely equivalent with$a['color'] = 'red';$a['taste'] = 'sweet';$a['shape'] = 'round';$a['name'] = 'apple';$a[] = 4; // key will be 0$b[] = 'a';$b[] = 'b';$b[] = 'c';// will result in the array array(0 => 'a' , 1 => 'b' , 2 => 'c'),// or simply array('a', 'b', 'c')?>
例子 11-6. 使用 array()
<?php// Array as (property-)map$map = array( 'version' => 4, 'OS' => 'Linux', 'lang' => 'english', 'short_tags' => true );// strictly numerical keys$array = array( 7, 8, 0, 156, -10 );// this is the same as array(0 => 7, 1 => 8, ...)$switching = array( 10, // key = 0 5 => 6, 3 => 7, 'a' => 4, 11, // key = 6 (maximum of integer-indices was 5) '8' => 2, // key = 8 (integer!) '02' => 77, // key = '02' 0 => 12 // the value 10 will be overwritten by 12 );// empty array$empty = array();?>例子 11-7. 集合
<?php$colors = array('red', 'blue', 'green', 'yellow');foreach ($colors as $color) { echo Do you like $color?/n;}?>上例將輸出: Do you like red?Do you like blue?Do you like green?Do you like yellow? 直接改變數組的值在 php 5 中可以通過引用傳遞來做到。之前的版本需要需要採取別的方法:
例子 11-8. 集合
<?php// php 5foreach ($colors as &$color) { $color = strtoupper($color);}unset($color); /* 確保下面對 $color 的覆蓋不會影響到前一個數組單元 */// 之前版本的方法foreach ($colors as $key => $color) { $colors[$key] = strtoupper($color);}print_r($colors);?>上例將輸出: Array( [0] => RED [1] => BLUE [2] => GREEN [3] => YELLOW) 本例產生一個基於一的數組。
例子 11-9. 基於一的數組
<?php$firstquarter = array(1 => 'January', 'February', 'March');print_r($firstquarter);?>上例將輸出: Array( [1] => 'January' [2] => 'February' [3] => 'March')*/?> 例子 11-10. 填充數組
<?php// fill an array with all items from a directory$handle = opendir('.');while (false !== ($file = readdir($handle))) { $files[] = $file;}closedir($handle);?>數組是有序的。也可以使用不同的排序函數來改變順序。更多信息參見數組函數。可以用 count() 函數來數出數組中元素的個數。
例子 11-11. 數組排序
<?phpsort($files);print_r($files);?>因為數組中的值可以為任意值,也可是另一個數組。這樣可以產生遞歸或多維數組。
例子 11-12. 遞歸和多維數組
<?php$fruits = array ( fruits => array ( a => orange, b => banana, c => apple ), numbers => array ( 1, 2, 3, 4, 5, 6 ), holes => array ( first, 5 => second, third ) );// Some examples to address values in the array aboveecho $fruits[holes][5]; // prints secondecho $fruits[fruits][a]; // prints orangeunset($fruits[holes][0]); // remove first// Create a new multi-dimensional array$juices[apple][green] = good;?>需要注意數組的賦值總是會涉及到值的拷貝。需要在復制數組時用引用符號(&)。
<?php$arr1 = array(2, 3);$arr2 = $arr1;$arr2[] = 4; // $arr2 is changed, // $arr1 is still array(2,3)$arr3 = &$arr1;$arr3[] = 4; // now $arr1 and $arr3 are the same?>
3. PHP遍歷目錄下的圖片,按順序顯示問題
<?php
error_reporting(0);
echo培和鉛"<html><head><title>圖片</title></head><bodybgcolor=000000><center><fontsize=2color=red>";//輸出html相關代碼
$page棚配=$_GET['page'];//獲取當前頁數
$max=3;//設置每頁顯示圖片最大張數
$dir="./image/";
$handle=opendir($dir);//當前目錄
while(($file=readdir($handle))!==false){//遍歷該php文件所在目錄
list($filesname,$kzm)=explode(".",$file);//獲取擴展名
if($kzm=="gif"or$kzm=="jpg"or$kzm=="JPG"or$kzm=="png"){//文件過濾
if(!is_dir('./'.$file)){//文件夾過濾
$array[]=$file;//把符合條件的文件名存入數組
$i++;//記錄圖片總張數
}
}
}
for($j=$max*$page;$j<($max*$page+$max)&&$j<$i;++$j){//循環條件控制顯示圖片張數
echo"<imgwidht=200height=200src=image\".$array[$j].">"."配好<br>";//輸出圖片數組
}
$Previous_page=$page-1;
$next_page=$page+1;
if($Previous_page<0){
echo"上頁";
echo"<ahref=?page=$next_page>下頁</a>";
}elseif($page<=$i/$max){
echo"<ahref=?page=$Previous_page>上頁</a>";
echo"<ahref=?page=$next_page>下頁</a>";
}else{
echo"<ahref=?page=$Previous_page>上頁</a>";
echo"下頁";
}
echo"</center></body></html>";
?>
4. php中怎麼列印數組啊
php中列印數組的步驟如下:
1、首先在編輯器中的菜單欄中點擊文件,然後點擊新建。
5. php裡面怎麼新建數組
php裡面新建數據可以通過兩種方式,一種是通過array函數來創建,另一種就是通過賦值[]來創建。
<?php
$arr1=array(1,2,3,4);
var_mp($arr1);
$arr2[0]=1;
$arr2[1]=2;
$arr2[2]=3;
$arr2[3]=4;
var_mp($arr2);
6. php如何創建包含所有大寫字母的數組
新建一個php文件,命名為test.php,用於講解php如何將數組中所有字母改為大寫。