Home php教程 php手册 如何判断php数组的维度

如何判断php数组的维度

Jun 06, 2016 pm 08:31 PM
php array judgment Dimensions

本篇文章是对判断php数组维度的代码进行了详细的分析介绍, 需要的朋友参考下

如下所示:

复制代码 代码如下:


/**
* 返回数组的维度
* @param [type] $arr [description]
* @return [type] [description]
*/
function arrayLevel($arr){
$al = array(0);
function aL($arr,&$al,$level=0){
if(is_array($arr)){
$level++;
$al[] = $level;
foreach($arr as $v){
aL($v,$al,$level);
}
}
}
aL($arr,$al);
return max($al);
}

$arr = array(
'0'=>'0',
);

echo arrayLevel($arr);
?>

,免备案空间,香港虚拟主机,美国服务器
Statement of this Website
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP email detection: Determine whether the email has been sent successfully. PHP email detection: Determine whether the email has been sent successfully. Sep 19, 2023 am 09:16 AM

PHP email detection: Determine whether the email has been sent successfully. When developing web applications, you often need to send emails to communicate with users. Whether it is registration confirmation, password reset, or sending notifications, the email function is an indispensable part. However, sometimes we cannot ensure whether the email is actually sent successfully, so we need to perform email detection and determine whether the email has been sent successfully. This article will introduce how to use PHP to implement this function. 1. Use SMTP server to send emails. First, we need to use SM

How to increase the dimension of numpy How to increase the dimension of numpy Nov 22, 2023 am 11:48 AM

How to add dimensions in numpy: 1. Use "np.newaxis" to add dimensions. "np.newaxis" is a special index value used to insert a new dimension at a specified position. You can use np.newaxis at the corresponding position. To increase the dimension; 2. Use "np.expand_dims()" to increase the dimension. The "np.expand_dims()" function can insert a new dimension at the specified position to increase the dimension of the array.

How to determine how many arrays there are in php How to determine how many arrays there are in php Aug 04, 2023 pm 05:40 PM

There are several ways to determine an array in PHP: 1. Use the count() function, which is suitable for all types of arrays. However, it should be noted that if the parameter passed in is not an array, the count() function will return 0; 2. Use the sizeof() function, which is more used to maintain compatibility with other programming languages; 3. Custom functions, By using a loop to traverse the array, each time it is traversed, the counter is incremented by 1, and finally the length of the array is obtained. Custom functions can be modified and expanded according to actual needs, making them more flexible.

An exploration of performance optimization techniques for PHP arrays An exploration of performance optimization techniques for PHP arrays Mar 13, 2024 pm 03:03 PM

PHP array is a very common data structure that is often used during the development process. However, as the amount of data increases, array performance can become an issue. This article will explore some performance optimization techniques for PHP arrays and provide specific code examples. 1. Use appropriate data structures In PHP, in addition to ordinary arrays, there are some other data structures, such as SplFixedArray, SplDoublyLinkedList, etc., which may perform better than ordinary arrays in certain situations.

jQuery usage practice: several ways to determine whether a variable is empty jQuery usage practice: several ways to determine whether a variable is empty Feb 27, 2024 pm 04:12 PM

jQuery is a JavaScript library widely used in web development. It provides many simple and convenient methods to operate web page elements and handle events. In actual development, we often encounter situations where we need to determine whether a variable is empty. This article will introduce several common methods of using jQuery to determine whether a variable is empty, and attach specific code examples. Method 1: Use the if statement to determine varstr="";if(str){co

Effective implementation of array union in PHP Effective implementation of array union in PHP Apr 30, 2024 pm 01:03 PM

An effective way to implement array union in PHP: use the array_merge() function to merge multiple arrays, but not merge duplicate values. Combine array_unique() and array_merge() to merge arrays and keep duplicate values. Create a custom function to merge arrays based on specific requirements, such as merging sorted arrays.

How to determine whether a date is the previous day in Go language? How to determine whether a date is the previous day in Go language? Mar 24, 2024 am 10:09 AM

Question: How to determine whether the date is the previous day in Go language? In daily development, we often encounter situations where we need to determine whether the date is the previous day. In the Go language, we can implement this function through time calculation. The following will be combined with specific code examples to demonstrate how to determine whether the date is the previous day in Go language. First, we need to import the time package in the Go language. The code is as follows: import("time") Then, we define a function IsYest

What is the function in PHP to determine if an array is empty? What is the function in PHP to determine if an array is empty? Aug 03, 2023 pm 05:15 PM

The functions that PHP uses to determine if an array is empty are the "empty()" function and the "count()" function. 1. The "empty()" function is used to determine whether a variable is empty, including determining whether an array is empty. Its syntax is "empty($variable)"; 2. The "count()" function is used to count arrays. The number of elements, the syntax is "count($array)".

See all articles