如何使用数组反向方法在PHP中不使用数组反向 [英] How to reverse an array in php WITHOUT using the array reverse method

查看:51
本文介绍了如何使用数组反向方法在PHP中不使用数组反向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何不使用array_reverse方法来反转数组.我有一个称为反向数组的数组,这是我要反向的数组.我的代码如下.有人可以指出我做错了什么,因为我找不到在其他地方以这种方式反转阵列的任何示例.我的代码在下面.

I want to know how to reverse an array without using the array_reverse method. I have an array called reverse array which is the one i want to reverse. My code is below. could someone point out what i am doing wrong as I cannot find any example of reversing an array this way anywhere else. my code is below.

<?php

//Task 21 reverse array

$reverseArray = array(1, 2, 3, 4);
$tmpArray = array();
$arraySize = sizeof($reverseArray);

for($i<arraySize; $i=0; $i--){
    echo $reverseArray($i);
}

?>

推荐答案

<?php
  $array = array(1, 2, 3, 4);
  $size = sizeof($array);

  for($i=$size-1; $i>=0; $i--){
      echo $array[$i];
  }
?>

这篇关于如何使用数组反向方法在PHP中不使用数组反向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆