search
Homephp教程php手册php二维数组循环程序代码

在php中数组分为一维数组与多维数组,如果我们要循环二维数组我们可以直接使用foreach与for来遍历即可,下面我来给大家介绍几个二维数组循环的实现有需要了解的朋友可进入参考。

for循环遍历二维数组

 代码如下 复制代码

print_r($order_data_info);

Array
(
[0] => stdClass Object ( [countOrder] => 3 [amntTotal] => 2380.00 [name] => 测试版 )
[1] => stdClass Object ( [countOrder] => 1 [amntTotal] => 2380.00 [name] => VIP版 )
[2] => stdClass Object ( [countOrder] => 2 [amntTotal] => 4760.00 [name] => 个人版 )
)


$order_length = sizeof($order_data_info);
for($i=0;$i{
    $order_data_info[$i]->amntTotal = money($order_data_info[$i]->amntTotal);
}

print_r($order_data_info);

Array
(
[0] => Array ( [countOrder] => 3 [amntTotal] => 2380.00 [name] => 测试版 )
[1] => Array ( [countOrder] => 1 [amntTotal] => 2380.00 [name] => VIP版 )
[2] => Array ( [countOrder] => 2 [amntTotal] => 4760.00 [name] => 个人版 )
)

$order_length = sizeof($order_data_info);
for($i=0;$i{
    $order_data_info[$i]['amntTotal'] = money($order_data_info[$i]['amntTotal']);
}


foreach语句用于循环遍历数组。

每进行一次循环,当前数组元素的值就会被赋值给 value 变量(数组指针会逐一地移动) - 以此类推

 代码如下 复制代码

foreach($array as $key)
{
      if(xxxx)
      {
             break; //break 会终止循环
      }
      if(zzz)
      {
             continue;  //continue 会终止本次循环,此刻会进入下一个循环;
      }
}

 代码如下 复制代码

 $team = array('lk','ok');
 $book = array('linux服务器配置与管理',$team);
 
 foreach($book as $k=>$val)  //意思是for  $book  each  $value( as )
  if( is_array($val) ) foreach( $val as $value) echo $value.'
';
  else echo $k.'=>'.$val.'
';
?>

例2

 代码如下 复制代码


             
$array = array('塞班(symbian)'=>array(1=>'s60v3横版',2=>'s60v3',3=>'s60v5'),
    '安卓(android)'=>array(4=>'android2.1及以上版本',6=>'Android 1.5',7=>'Android 1.6',8=>'Android 2.1',9=>'Android 2.2',10=>'Android 2.3',11=>'Android 3.0',12=>'Android 3.1',12=>'Android 3.2',12=>'Android 4.0',12=>'Android 4.1',12=>'Android 4.2'),
    'wp7(Windowsphone)'=>array(5=>'Windows Phone 7系统')
    );

 

                foreach( $array as $c=> $cc )
                {
                    echo '';
                    foreach($cc as $v => $vv)
                    {
                        if( $addRow["sjos"]== $v ) { $select="selected";}else{ $select="";}
                        echo '';
                    }
                   
                }
?>



教程地址:

欢迎转载!但请带上文章地址^^

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.