PHP100 2019-03-27
代码如下:
$capitals = array( 'Alabama' => 'Montgomery', 'Alaska' => 'Juneau', 'Arizona' => 'Phoenix' ); $states = array_flip($capitals); // $states = array( // 'Montgomery' => string 'Alabama', // 'Juneau' => string 'Alaska', // 'Phoenix' => string 'Arizona' // );
代码如下:
$stateCapitals = array( 'Alabama' => 'Montgomery', 'Alaska' => 'Juneau', 'Arizona' => 'Phoenix' ); $countryCapitals = array ( 'Australia' => 'Canberra', 'Austria' => 'Vienna', 'Algeria' => 'Algiers' ); $capitals = array_merge($stateCapitals, $countryCapitals);
代码如下:
function capitalize($element) { $element = strtolower($element); return ucwords($element); } $capitals = array( 'Alabama' => 'montGoMEry', 'Alaska' => 'Juneau', 'Arizona' => 'phoeniX' ); $capitals = array_map("capitalize", $capitals);
代码如下:
$capitals = array( 'Arizona' => 'Phoenix', 'Alaska' => 'Juneau', 'Alabama' => 'Montgomery' ); ksort($capitals);
代码如下:
$capitals = array( 'Arizona' => 'Phoenix', 'Alaska' => 'Juneau', 'Alabama' => 'Montgomery' ); shuffle($capitals);
代码如下:
$capitals = array( 'Arizona' => 'Phoenix', 'Alaska' => 'Juneau', 'Alabama' => 'Montgomery' ); if (in_array("Juneau", $capitals)) { echo "Exists!"; } else { echo "Does not exist!"; }
代码如下:
$capitals = array( 'Arizona' => 'Phoenix', 'Alaska' => 'Juneau', 'Alabama' => 'Montgomery' ); if (array_key_exists("Alaska", $capitals)) { echo "Key exists!"; } else { echo "Key does not exist!"; }
代码如下:
$capitals = array( 'Arizona' => 'Phoenix', 'Alaska' => 'Juneau', 'Alabama' => 'Montgomery' ); $state = array_search('Juneau', $capitals); // $state = 'Alaska'
代码如下:
$capitals = array( 'Arizona' => 'Phoenix', 'Alaska' => 'Juneau', 'Alabama' => 'Montgomery' ); $arrayObject = new ArrayObject($capitals); foreach ($arrayObject as $state => $capital) { printf("The capital of %s is %s<br />", $state, $capital); } // The capital of Arizona is Phoenix // The capital of Alaska is Juneau // The capital of Alabama is Montgomery
<?php. if (!empty($_POST)) {. $data1 = $_POST["data1"];$data2 = $_POST["data2"];$fuhao = $_POST["fuh