-1

请问我怎样才能实现这样的目标:

A-FIRSTNAME
B-LASTNAME
C-MIDDLENAME
D-PHONE

她是我的密码

<php 

   $alphabet = range('A','D');
   for ($i = 1; $i<4; $i++){
      $i2 = $i;
      echo $alphabet[$i2]."-FIRSTNAME";
      echo $alphabet[$i2]."-LASTNAME";
      echo $alphabet[$i2]."-MIDDLENAME";
      echo $alphabet[$i2]."-PHONE";
      $i2++;
  }

?>

4

3 回答 3

0

你可以这样做:

$arr = array('FIRSTNAME','LASTNAME','MIDDLENAME','PHONE');

$i = 0;
foreach (range('A', 'D') as $alphabet) {
    echo $alphabet .'-'. $arr[$i] . '\n';
    $i++;
}
于 2018-04-20T01:22:17.843 回答
0

PHP > 7 :

<?php
$phrases = [
    'FIRSTNAME', 
    'LASTNAME', 
    'MIDDLENAME',
    'PHONE'
];
$chars  = range('A','Z');
foreach ($phrases as $index => $phrase) {
    echo ($chars[$index] ?? '?') . ' => ' . $phrase;
}

PHP < 7 :

<?php
$phrases = [
    'FIRSTNAME', 
    'LASTNAME', 
    'MIDDLENAME',
    'PHONE'
];
$chars  = range('A','Z');
foreach ($phrases as $index => $phrase) {
    echo (isset($chars[$index]) ? $chars[$index] : '?') . ' => ' . $phrase;
}
于 2018-04-20T01:22:38.600 回答
0
<?php 

   $alphabet = range('A','D');


   for ($i = 0; $i<4; $i++){

      echo nl2br($alphabet[$i]."-FIRSTNAME\n");
      echo nl2br($alphabet[$i]."-LASTNAME\n");
      echo nl2br($alphabet[$i]."-MIDDLENAME\n");
      echo nl2br($alphabet[$i]."-PHONE\n");
      echo nl2br("\n");
      echo nl2br("\n");
  }

?>
于 2018-04-20T01:25:10.913 回答