PHP数组(普通、二维)

<?php
    header("Content-Type: text/html; charset=utf-8");
    $arrayName = array("jsp","asp","php");
    print_r($arrayName);
    echo "<br>",$arrayName[1];
    echo "<br>";
    $array2 = array("1" => "電", "2" => "子","3" => "辞", "4" => "書");
    print_r($array2);
?>
Array ( [0] => jsp [1] => asp [2] => php ) 
asp
Array ( [1] => 電 [2] => 子 [3] => 辞 [4] => 書 ) 

<?php
    header("Content-Type: text/html; charset=utf-8");
    $arrayName = array("first" => "1", "second" => "2","third" => "3");
    print_r($arrayName);
    echo "<br>";
    $arrayName["third"]="8";
    print_r($arrayName);
?>
Array ( [first] => 1 [second] => 2 [third] => 3 ) 
Array ( [first] => 1 [second] => 2 [third] => 8 ) 

<?php
    header("Content-Type: text/html; charset=utf-8");
    $arrayName = array(
            "書類" => array("文学","歴史","地理"), 
            "体育物" => array("s" => "サッカー","b" => "バスケットボール"), 
            "果物" => array("オレンジ", "p" => "ブドウ","リンゴ"), 
    );
    print_r($arrayName);
    echo "<br>";
?>
Array ( [書類] => Array ( [0] => 文学 [1] => 歴史 [2] => 地理 ) [体育物] => Array ( [s] => サッカー [b] => バスケットボール ) [果物] => Array ( [0] => オレンジ [p] => ブドウ [1] => リンゴ ) ) 

<?php
    header("Content-Type: text/html; charset=utf-8");
    $arrayName = array(
            "書類" => array("文学","歴史","地理"), 
            "体育物" => array("s" => "サッカー","b" => "バスケットボール"), 
            "果物" => array("オレンジ", "p" => "ブドウ","リンゴ"), 
    );
    foreach ($arrayName as $key) {
        print_r($key);
        echo "<br>";
        foreach ($key as $mono => $value) {
            echo $value,"<br>";
        }
        echo "<br>";
    }
?>
Array ( [0] => 文学 [1] => 歴史 [2] => 地理 ) 
文学
歴史
地理

Array ( [s] => サッカー [b] => バスケットボール ) 
サッカー
バスケットボール

Array ( [0] => オレンジ [p] => ブドウ [1] => リンゴ ) 
オレンジ
ブドウ
リンゴ

<?php
    header("Content-Type: text/html; charset=utf-8");
    $str="a,b,c";
    $strs=explode(",", $str);//字符串转换为数组
    //explode(delimiter, string) delimiter分割字符 
    print_r($strs);
?>
Array ( [0] => a [1] => b [2] => c ) 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值