是我没表达清楚吧.是这个意思:
有一数组: array( 232, 314, 1223, 42123, 432);
现在提供其中一单元,如 1223,只是想把1223提前一位.请问应该怎么操作呢?

解决方案 »

  1.   

    自己写个函数不就解决了。  首先取得现有数组的个数count($a);
      然后新建中间数组,你想提前的元素位置做个标记,前面的不变,
      标志的地方换成新的,然后他原来的置后,最后原样输出,
      最后返回新数组就应该可以解决你的问题。 这是解决思路。
      

  2.   

    <?php
    $a_array = array('123','234','345','456');
    $num = count($a_array); for($i=0; $i<$num; $i++) {
    if($a_array[$i] == $txtValue) {
    if(i!==0) {
    $tmp = $a_array[$i];
    $a_array[$i] = $a_array[$i-1];
    $a_array[$i-1] = $tmp;
    }
    }
    else {
    echo $a_array[i].'<br/n>';
    }
    }
    print_r($a_array);?>
    <html>
    <body>
    <form method="POST" action="phpinfo.php">
    <input type="text" name="txtValue">
    <input type="submit" value="Click">
    </form>
    </body>
    </html>
      

  3.   

    <?php
    $a_array = array('123','234','345','456');
    $num = count($a_array); for($i=0; $i<$num; $i++) {
    if($a_array[$i] == $txtValue) {
    if(i!==0) {
    $tmp = $a_array[$i];
    $a_array[$i] = $a_array[$i-1];
    $a_array[$i-1] = $tmp;
    }
    }
    else {
    echo $a_array[i].'<br/n>';
    }
    }
    print_r($a_array);?>
    <html>
    <body>
    <form method="POST" action="phpinfo.php">
    <input type="text" name="txtValue">
    <input type="submit" value="Click">
    </form>
    </body>
    </html>
      

  4.   

    sorry 
    if(i!==0)应改为 if($i!==0)
      

  5.   

    a[i] 和 a[i-1] 交换就可以了