php数组,php数组长度
php数组,php数组长度
$arr=array('zz'=>'郑州','北京',9=>'上海','郑州');
print_r($arr);
$c=array_unique($arr);//消除重复的元素值,并进行索引排列
print_r($c);
$b=array_values($arr);//重新排序数组
print_r($b);
$arr1=array('郑州','河北','上海','北京');
$arr2=array('开封','洛阳','濮阳');
$arr3=array_merge($arr1,$arr2);//合并数组$arr1,$arr2.
echo '
';<br> print_r($arr3);<br> <br> <br> <br> <br> <br> $str="jjjjjj5555455ccccdddd565dfddfd";<br> $arr=preg_split('/\d{1,}/', $str);//正则表达式<br> print_r($arr);<br> <br> <br> <br> $st="北京,上海,天津,郑州,广东";<br> $arr=explode(',', $st);<br> print_r($arr);<br> $ss=implode("====",$arr);<br> echo '<pre class="brush:php;toolbar:false">'; <p> echo $ss;<br> foreach ($arr as $v){<br> echo '</p><pre class="brush:php;toolbar:false">';<br> echo $v;<br> }<br> <br> <br> <br> $arr[][]='ok';<br> $arr[][]=[10,20,30];<br> $arr[][]='hello';<br> $arr[][]=array('hn'=>'河南',60,'zz'=>'郑州',array(100,200));<br> echo '<pre class="brush:php;toolbar:false">';<br> print_r($arr);<br> echo $arr[1][0][2];<br> <br> <br> $age=$sage=$stage=50; <p> echo $age;<br> echo '</p><pre class="brush:php;toolbar:false">';<br> echo $sage;<br> echo $stage;<br> <br> <br> <br> <br> <br> //二维数组<br> $arr=array(10,'zz'=>'郑州',array(20,30,40,50),array(60,70,80));<br> echo '<pre class="brush:php;toolbar:false">';<br> print_r($arr);<br> echo $arr[2][0];<br> echo sizeof($arr,1);<br> echo count($arr);<br> foreach($arr as $v){<br> if(!is_array($v)){<br> echo $v.'<br>';<br> continue;<br> }<br> foreach ($v as $vv){<br> echo $vv.'<br>';<br> }<br> } <br> <p> <br> $a=[10,20,30,40];<br> echo in_array(20, $a);//查询数组中某个值是否存在如果存在则返回1<br> if (array_search(20, $a)===false){<br> echo '没有找到';<br> }else {<br> echo '找到了,位置是:'.array_search(20, $a);<br> }<br> <br> <br> //建议指定序列的字符数<br> $arr=range('a','z');<br> $arr=range(1,100,3);<br> echo '</p><pre class="brush:php;toolbar:false">';<br> print_r($arr);<br>substr截取数值,in_array 判断是否存在数组中<br> $arr=array('12','133','135','138');<br> $aa='1202';<br> if (in_array(substr($aa,0,2),$arr)) {<br> echo '存在'.$aa;<br> }else {<br> echo '不存在';<br> } <p> </p> <p> </p> <p>is_array判断是不是数组<br> $arr=20;<br> if (is_array($arr)){<br> echo '是数组';<br> print_r($arr);<br> }else {<br> echo '不是数组';<br> echo $arr;<br> }<br> <br> <br> <br> <br> //利用循环语句给空数组赋10个值(1-100之间的随机整数)<br> $arr=array();<br> for ($i=0;$i $arr[]=mt_rand(1,100);<br> }<br> echo'排序后:';<br> foreach ($arr as $v){</p> <p> echo $v.' ';<br> }<br> echo '</p><hr>'; <p>// //实现排序算法冒泡排序<br> for ($m=0;$m<count></count> for ($n=0;$n<count></count> if ($arr[$n]>$arr[$n+1]){<br> $t = $arr[$n];<br> $arr[$n]=$arr[$n+1];<br> $arr[$n+1]=$t;<br> }<br> <br> }<br> }</p> <p> echo'排序后:';<br> foreach ($arr as $v){<br> echo $v.'  ';<br> }</p> <p> <br> $arr=array();<br> $arr[]=10;<br> $arr[]=20;<br> $arr[]=30;<br> $arr[]=40;<br> $arr[]=50;<br> echo $arr[2];</p> <p> </p> <p> </p> <p> </p> <p> echo rand(1,3).','.rand().','.rand(10,100);//随机数<br> echo mt_rand(1,100).'--'.mt_rand().'--'.mt_rand(1,3);//生成更好的随机数</p> <p> </p> <p> </p> <p>//声明一个数组随机赋予10个数字(1-100)范围内的整数<br> $arr=array();<br> for ($i=0;$i $arr[]=mt_rand(1,100);<br> }<br> echo '</p><pre class="brush:php;toolbar:false">';<br> print_r($arr); <p><br> sort($arr);//排序后输出数组<br> print_r($arr);</p> <p> </p> <p><br> $arr1=array(10,52,34,40);//声明数组<br> $arr2=[10,20,30];<br> $arr3=array('bj'=>'北京','sh'=>'上海');<br> echo '</p><pre class="brush:php;toolbar:false">';<br> var_dump($arr1);//打印数组并且输出类型<br> print_r($arr3);//打印输出数组 <p> echo $arr3['bj'];//输出北京<br> echo '<br>';<br> echo $arr1[2];/输出30,从0开始</p> <p> foreach ($arr3 as $k=>$v){<br> echo $v;//输出值,$k输出下标<br> }<br> $arr3[]='郑州'; //给数组增加元素在数组的后面<br> $arr3['sz']='深圳';<br> array_unshift($arr3,'杭州','青岛');//在数组的前面增加元素<br> unset($arr3['bj']);//删除$arr3数组中的bj元素</p> <p><br> $bj= array_shift($arr3);//移除数组中的第一个元素,取出来赋给bj并输出<br> echo $bj;</p> <p> $sz=array_pop($arr3);//移除数组中的最后一个元素,并赋值<br> echo $sz;</p> <p><br> foreach ($arr3 as $k=>$v){<br> echo $k.'=>'.$v;<br> }</p> <p> </p> <p>sort($arr1);//升序,从小到大<br> rsort($arr1);//降序,从大到小<br> print_r($arr1);<br> echo count($arr1);</p> <p> </p> <p> </p> <p> </p> <p><br> $a=array(4,8);<br> echo count($a);//返回数组的元素个数2</p> <p> </p> <p> $str='日,一,二,三,四,五,六';<br> $arr=explode(',',$str);//将一个字符串按照字符串间隔分成数组<br> // print_r($arr);<br> $w=date('w');<br> echo '今天是:星期'.$arr[$w];</p> <p> </p> <p> $h=date('G');<br>// if ($h>=8 && $h// echo '上午好';<br>// }else if ($h>=13 && $h// echo'下午好';<br>// }else if ($h>=19 && $h// echo '晚上好';<br>// }elseif ($h>=22 && $h// echo '夜深了,请注意休息';<br>// }elseif ($h>=6 && $h// echo '早上好';<br>// }</p> <p> </p> <p><br>// echo date ( 'Y-m-d H:i:s' );<br>// $d = date ( 'w' );<br>// if ($d == 0) {<br>// echo '今日:星期日';<br>// }<br>// if ($d == 1) {<br>// echo '今日:星期一';<br>// }<br>// if ($d == 2) {<br>// echo '今日:星期二';<br>// }<br>// if ($d == 3) {<br>// echo '今日:星期三';<br>// }<br>// if ($d == 4) {<br>// echo '今日:星期四';<br>// }<br>// if ($d == 5) {<br>// echo '今日:星期五';<br>// }<br>// if ($d == 6) {<br>// echo '今日:星期六';<br>// }</p> <p>?><br> </p>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
