源码之家:www.mycodes.net

PHP

php 调试 汇总 数组

$arr_age = array(18, 20, 25);
print_r($arr_age);

 

foreach ($colors as $value) {
  echo "$value <br>";
}

$num = count($arr);
for($i=0;$i<$num;++$i){
echo $arr[$i].'<br />';
}

 

foreach($arr as $k=>$v){
echo $k."=>".$v."<br />";
}

 

array_flip($pays)  //数组反转  key 和 value 反转

 


 // 示例 1
$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2


// 示例 2
$data = "foo:*:1023:1000::/home/foo:/bin/sh";
list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
echo $user; // foo
echo $pass; // *

 

 

$str = 'one|two|three|four';
// 正数的 limit
print_r(explode('|', $str, 2));

[0] => one
[1] => two|three|four


// 负数的 limit
print_r(explode('|', $str, -1));

[0] => one
[1] => two
[2] => three

 

 

array_push将一个或多个单元压入数组的末尾(入栈)

$stack = array("Java""Php""C++");  

array_push($stack"C#""Ruby"array('jsp''Asp'));  


array_pop() 将数组最后一个单元弹出(出栈)

array_pop($stack);  

array_shift()将数组开头的单元移出数组 

array_unshift()在数组开头插入一个或多个单元

 $transport = array('foot', 'bike', 'car', 'plane');
 $mode = current($transport); //$mode = 'foot';
 $mode = next($transport);   // $mode ='bike';
 $mode = current($transport); //$mode = 'bike';
 $mode = prev($transport);   // $mode ='foot';
 $mode = end($transport);    // $mode ='plane';
 $mode = current($transport); //$mode = 'plane';


函数用全局变量

$vvv = '';

function ddd()

{

    global $vvv;

}

 

 

 

 

 

 

 

 

 

 

联系我们Contact

Copyright © 2013 - 2024 mycodes.net All rights reserved.

公司位置