0

我检查了每个变量,但每个变量都在回显经过验证的结果,所以问题出在数组中。当我尝试回显 56 个值的完整列表时,我只得到 11 个。

所有变量都是 SET 之前,我检查例如,如果我回显 $uno,我得到一个值 12.. 那么为什么数组上没有这个值。

这是我的代码..

$items = array(
  $uno => "item1",
  $dos => "item2",
  $tres => "item3",
  $cuatro => "item4",
  $cinco => "item5",
  $seis => "item6",
  $siete => "item7",
  $ocho => "item8",
  $nueve => "item9",
  $diez => "item10",
  $once => "item11",
  $doce => "item12",
  $trece => "item13",
  $catorce => "item14",
  $quince => "item15",
  $dieciseis => "item16",
  $diecisiete => "item17",
  $dieciocho => "item18",
  $diecinueve => "item19",
  $veinte => "item20",
  $veintiuno => "item21",
  $veintidos => "item22",
  $veintitres => "item23",
  $veinticuatro => "item24",
  $veinticinco => "item25",
  $veintiseis => "item26",
  $veintisiete => "item27",
  $veintiocho => "item28",
  $veintinueve => "item29",
  $treinta => "item30",
  $treintayuno => "item31",
  $treintaydos => "item32",
  $treintaytres => "item33",
  $treintaycuatro => "item34",
  $treintaycinco => "item35",
  $treintayseis  => "item36",
  $treintaysiete => "item37",
  $treintayocho => "item38",
  $treintaynueve => "item39",
  $cuarenta => "item40",
  $cuarentayuno => "item41",
  $cuarentaydos => "item42",
  $cuarentaytres => "item43",
  $cuarentaycuatro => "item44",
  $cuarentaycinco => "item45",
  $cuarentayseis => "item46",
  $cuarentaysiete => "item47",
  $cuarentayocho => "item48",
  $cuarentaynueve => "item49",
  $cincuenta => "item50",
  $cincuentayuno => "item51",
  $cincuentaydos => "item52",
  $cincuentaytres => "item53",
  $cincuentaycuatro => "item54",
  $cincuentaycinco => "item55",
  $cincuentayseis => "item56", 
  );

PHP 代码

<?PHP 
echo "<strong>Original</strong><br />";
foreach($items as $k => $v){
    echo $k . " = " . $v . "<br />";
}

asort($items);
echo "<strong>Ascending Sort</strong><br />";
foreach($items as $k => $v){
    echo $k . " = " . $v . "<br />";
}

arsort($items);
echo "<strong>Descending Sort</strong><br />";
foreach($items as $k => $v){
    echo $k . " = " . $v . "<br />";
}

?>

我把它作为输出..

Original
11 = item30
5 = item35
12 = item20
8 = item42
7 = item45
4 = item44
6 = item47
9 = item41
10 = item37
2 = item46
0 = item56
Ascending Sort
12 = item20
11 = item30
5 = item35
10 = item37
9 = item41
8 = item42
4 = item44
7 = item45
2 = item46
6 = item47
0 = item56
Descending Sort
0 = item56
6 = item47
2 = item46
7 = item45
4 = item44
8 = item42
9 = item41
10 = item37
5 = item35
11 = item30
12 = item20
4

1 回答 1

0

数组键必须是唯一的。因此,请使用 itemNN。

$items = array(
  "item1" => $uno,
  "item2" => $dos,
  "item3" => $tres,
...

甚至不使用字符串作为键

$items = array(
  1 => $uno,
  2 => $dos,
  3 => $tres,
...

甚至像这样

$items = array(
  1 => $uno,
  $dos,
  $tres,
...
于 2013-05-21T23:01:20.897 回答